change implementation to insertion-sort

parent 0fb676da
...@@ -2,16 +2,21 @@ ...@@ -2,16 +2,21 @@
#include<vector> #include<vector>
#include "sorting.h" #include "sorting.h"
using namespace std; using namespace std;
vector<int> sort_custom(vector<int>r){ vector<int> sort_custom (vector<int> data)
for(int i=0;i<r.size();i++){ {
for(int j=r.size()-1;j>=i;j--){ int i, j, tmp;
if(r[j-1]>r[j]){
int temp; for (i=1; i<data.size(); i++)
temp=r[j-1]; {
r[j-1]=r[j]; j=i;
r[j]=temp; tmp=data[i];
} while (j>0 && tmp<data[j-1])
} {
} data[j]=data[j-1];
return r; j--;
}
data[j]=tmp;
}
return data;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment