Commit 7083cfda authored by RAMYA NARAYANASAMY's avatar RAMYA NARAYANASAMY

change implementation to insertion-sort

parent 838eab18
#include "sorting.h" #include "sorting.h"
vector<int> sort_custom(vector<int> a) vector<int> sort_custom(vector<int> arr){
{ int i, key, j;
bool swapp = true; for (i = 1; i < arr.size(); i++)
while(swapp){ {
swapp = false; key = arr[i];
for (size_t i = 0; i < a.size()-1; i++) { j = i-1;
if (a[i]>a[i+1] ){
a[i] += a[i+1]; /* Move elements of arr[0..i-1], that are
a[i+1] = a[i] - a[i+1]; greater than key, to one position ahead
a[i] -=a[i+1]; of their current position */
swapp = true; while (j >= 0 && arr[j] > key)
} {
arr[j+1] = arr[j];
j = j-1;
} }
arr[j+1] = key;
} }
return a; return arr;
} }
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