Commit e2e63555 authored by KALPIT VEERWAL's avatar KALPIT VEERWAL

change implementation to insertion-sort

parent 4150af66
#include "sorting.h" #include "sorting.h"
#include<iostream> #include<iostream>
vector<int> sort_custom(vector<int> inp){ vector<int> sort_custom(vector<int> inp){
for (int i=0;i<inp.size();i++){ int i, key, j;
for (int j=1;j<inp.size();j++){ for (i = 1; i < inp.size(); i++)
if (inp[j-1]>inp[j]){ {
int temp=inp[j]; key = inp[i];
inp[j]=inp[j-1]; j = i-1;
inp[j-1]=temp; while (j >= 0 && inp[j] > key)
} {
} inp[j+1] = inp[j];
} j = j-1;
return inp; }
} inp[j+1] = key;
\ No newline at end of file }
return inp;
\ No newline at end of file
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