From c79408ec620729ebf5fb8a8e5c77a215c4b37379 Mon Sep 17 00:00:00 2001 From: Abhi Date: Fri, 21 Sep 2018 02:20:58 +0530 Subject: [PATCH] change implementation to insertion-sort --- sorting.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/sorting.cpp b/sorting.cpp index eb336f3..cadc8f0 100755 --- a/sorting.cpp +++ b/sorting.cpp @@ -3,17 +3,17 @@ using namespace std; vector sort_custom(vector v){ - int i, j; - int n=v.size(); - for (i = 0; i < n-1; i++){ - for (j = 0; j < n-i-1; j++){ - if (v[j] > v[j+1]){ - int temp; - temp=v[j]; - v[j]=v[j+1]; - v[j+1]=temp; - } - } + int value,j=0; + for(int i=1;i=0 && v[j]>value) + { + v[j+1] = v[j]; + j=j-1; + } + v[j+1]=value; } return v; -} \ No newline at end of file +} -- 2.24.1