Commit c79408ec authored by Abhi's avatar Abhi

change implementation to insertion-sort

parent 0ea14c1d
...@@ -3,17 +3,17 @@ ...@@ -3,17 +3,17 @@
using namespace std; using namespace std;
vector<int> sort_custom(vector<int> v){ vector<int> sort_custom(vector<int> v){
int i, j; int value,j=0;
int n=v.size(); for(int i=1;i<v.size();i++)
for (i = 0; i < n-1; i++){ {
for (j = 0; j < n-i-1; j++){ value = v[i];
if (v[j] > v[j+1]){ j=i-1;
int temp; while(j>=0 && v[j]>value)
temp=v[j]; {
v[j]=v[j+1]; v[j+1] = v[j];
v[j+1]=temp; j=j-1;
}
} }
v[j+1]=value;
} }
return v; return v;
} }
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