From 543e9de2b68f7be3942556079e81d74cdf4e4c82 Mon Sep 17 00:00:00 2001 From: Creator54 <34543609+Creator54@users.noreply.github.com> Date: Tue, 29 Oct 2019 15:26:22 +0530 Subject: [PATCH] support user input size,elements --- sorting/quickSort.c | 55 +++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/sorting/quickSort.c b/sorting/quickSort.c index 2ddd10b..cd948dd 100644 --- a/sorting/quickSort.c +++ b/sorting/quickSort.c @@ -4,35 +4,36 @@ */ #include -#define SIZE 6 //array size - -void partitionArray(int *a, int beg, int end, int *pivotLoc); -void quickSort(int *a, int beg, int end); +void partitionArray(int *j, int beg, int end, int *pivotLoc); +void quickSort(int *j, int beg, int end); int main(){ - int a[SIZE] = {5,2,6,1,3,4}; //unsorted array - int i; - - quickSort(a, 0, SIZE-1); //beg = 0 start index of array end = 5 last index of array - + int k; + printf("How many elements?\t"); + scanf("%d",&k); + int i,j[k]; + for(i=0;i a[right]){ + }else if(j[*pivotLoc] > j[right]){ //pivot element greater than right element. swap pivot and right element. - tmp = a[right]; - a[right] = a[*pivotLoc]; - a[*pivotLoc] = tmp; + tmp = j[right]; + j[right] = j[*pivotLoc]; + j[*pivotLoc] = tmp; *pivotLoc = right; //pivot is now pointing to right } //pivot pointing to right - while(a[*pivotLoc] >= a[left] && *pivotLoc != left){ //pivot element >= left element + while(j[*pivotLoc] >= j[left] && *pivotLoc != left){ //pivot element >= left element left++; //move left one position towards right } if(*pivotLoc == left){ //both left and right pointing at the same element of the array break; - }else if(a[*pivotLoc] < a[left]){ + }else if(j[*pivotLoc] < j[left]){ //pivot element smaller than left element. swap pivot and left element. - tmp = a[left]; - a[left] = a[*pivotLoc]; - a[*pivotLoc] = tmp; + tmp = j[left]; + j[left] = j[*pivotLoc]; + j[*pivotLoc] = tmp; *pivotLoc = left; //pivot is now pointing to left } } -}//partitionArray() ends here \ No newline at end of file +}//partitionArray() ends here