Commit cfa633d4 authored by TUSHAR AGARWAL's avatar TUSHAR AGARWAL

change implementation to insertion-sort

parent feba6dea
......@@ -2,13 +2,19 @@
using namespace std ;
vector<int> sort_custom(vector<int> data)
{
vector<int> arr(data.begin(), data.end()) ;
for(int i = 0; i < data.size(); i++)
{
for(int j = 0; j < data.size()-i-1; j++)
{
if (arr[j] > arr[j+1]) swap(arr[j],arr[j+1]) ;
}
}
return arr ;
}
\ No newline at end of file
int i, key, j;
vector<int> ans = data;
for (i = 1; i < data.size(); i++)
{
key = ans[i];
j = i-1;
while (j >= 0 && ans[j] > key)
{
ans[j+1] = ans[j];
j = j-1;
}
ans[j+1] = key;
}
return ans;
}
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