Commit a8f9232a authored by AMBATI SATVIK's avatar AMBATI SATVIK

change implementation to insertion-sort

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