From 88327f348cc809017bf329ed99a4c8d4c107bdf9 Mon Sep 17 00:00:00 2001 From: ANSH GUPTA <68772910+PROFESSORRQ@users.noreply.github.com> Date: Wed, 12 Aug 2020 15:51:55 +0530 Subject: [PATCH] updated quick sort algorithm Its a c++ program for quick sort --- quicksort.c | 48 ----------------------------------------------- quicksort.cpp | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 48 deletions(-) delete mode 100644 quicksort.c create mode 100644 quicksort.cpp diff --git a/quicksort.c b/quicksort.c deleted file mode 100644 index 116a852..0000000 --- a/quicksort.c +++ /dev/null @@ -1,48 +0,0 @@ -#include -#include -int quicksort(int*a, int len){ - quicksort_r(a,0,len-1); - return 0; -} -int quicksort_r(int* a,int start,int end){ - if (start>=end) { - return 0; - } - int pivot=a[end]; - int swp; - //set a pointer to divide array into two parts - //one part is smaller than pivot and another larger - int pointer=start; - int i; - for (i=start; i +using namespace std; +int partition(int A[],int lb,int ub) +{ + int pivot=A[lb]; + int start=lb; + int end=lb+1; + while(end<=ub) + { + if(A[end]>pivot) + { + end++; + start++; + } + + if(pivot>A[end]) + { + int temp=A[start]; + A[start]=A[end]; + A[end]=temp; + start++; + end++; + } + + } +return start; +} +void quicksort(int A[],int lb,int ub) +{ + if(lb>n; + int A[n]; + int lb=0;int ub=n-1; + for(int i=0;i>A[i]; + } + quicksort(A,lb,ub); + for(int i=0;i