Commit 76adf722 authored by DIDDI SAI KIRAN's avatar DIDDI SAI KIRAN

change implementation to insertion-sort

parent add2430f
#include<iostream> #include"sorting.h"
#include "sorting.h"
using namespace std; using namespace std;
vector<int> sort_custom(vector<int> v1){ vector<int> sort_custom( vector<int> a ){
int i, j; int i, key, j;
int n=v1.size(); int n=a.size();
for (i = 0; i < n-1; i++) { for (i = 1; i < n; i++)
for (j = 0; j < n-i-1; j++){ {
if (v1[j] > v1[j+1]) key = a[i];
swap(v1[j], v1[j+1]); j = i-1;
while (j >= 0 && a[j] > key)
{
a[j+1] = a[j];
j = j-1;
} }
a[j+1] = key;
} }
return v1; return a;
} }
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