change implementation to insertion-sort

parent 0fb676da
......@@ -2,16 +2,21 @@
#include<vector>
#include "sorting.h"
using namespace std;
vector<int> sort_custom(vector<int>r){
for(int i=0;i<r.size();i++){
for(int j=r.size()-1;j>=i;j--){
if(r[j-1]>r[j]){
int temp;
temp=r[j-1];
r[j-1]=r[j];
r[j]=temp;
vector<int> sort_custom (vector<int> data)
{
int i, j, tmp;
for (i=1; i<data.size(); i++)
{
j=i;
tmp=data[i];
while (j>0 && tmp<data[j-1])
{
data[j]=data[j-1];
j--;
}
data[j]=tmp;
}
}
return r;
return data;
}
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