-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquickSort.c
More file actions
72 lines (59 loc) · 1.34 KB
/
quickSort.c
File metadata and controls
72 lines (59 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include<stdio.h>
#include<stdlib.h>
int partition(int arr[],int low,int high,int n){
int pivot=arr[high],temp;
int i=low-1;
for(int p=low;p<high;p++){
if(arr[p] < pivot){
i++;
temp=arr[i];
arr[i]=arr[p];
arr[p]=temp;
}
}
temp=arr[i+1];
arr[i+1]=arr[high];
arr[high]=temp;
return i+1;
// while(low<high){
// while( low<n && arr[low]<=arr[pivot]){
// low++;
// }
// while( high>=0 && arr[high]>arr[pivot]){
// high--;
// }
// if(low<high){
// temp=arr[low];
// arr[low]=arr[high];
// arr[high]=temp;
// }
// }
// temp=arr[pivot];
// arr[pivot]=arr[high];
// arr[high]=temp;
// return high;
}
void quicksort(int arr[],int l,int h,int n){
if(l<h){
int p=partition(arr,l,h,n);
quicksort(arr,l,p-1,n);
quicksort(arr,p+1,h,n);
}
}
int main(){
int n;
printf("Enter the size of Array:\n");
scanf("%d",&n);
int arr[n];
printf("The Number in your array is :\n");
for(int i=0;i<n;i++){
arr[i]=rand()%200;
printf("%d ",arr[i]);
}
quicksort(arr,0,n-1,n);
printf("\nFinal Array is: \n");
for(int i=0;i<n;i++){
printf("%d ",arr[i]);
}
return 0;
}