Commit a8f9232a authored by AMBATI SATVIK's avatar AMBATI SATVIK

change implementation to insertion-sort

parent b440396f
...@@ -4,21 +4,18 @@ using namespace std; ...@@ -4,21 +4,18 @@ using namespace std;
vector<int> sort_custom(vector<int> v) vector<int> sort_custom(vector<int> v)
{ {
for(int i = 0; i < v.size(); i++) int i, key, j;
for (i = 1; i < v.size(); i++)
{ {
int count = 0; key = v[i];
for(int j = 0; j < v.size()-1; j++) j = i-1;
while (j >= 0 && v[j] > key)
{ {
if (v[j] > v[j+1]) { v[j+1] = v[j];
count++; j = j-1;
int temp = v[j];
v[j] = v[j+1];
v[j+1] = temp;
}
}
if (count==0) {
return v;
} }
v[j+1] = key;
} }
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