Commit cfa633d4 authored by TUSHAR AGARWAL's avatar TUSHAR AGARWAL

change implementation to insertion-sort

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