-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquickSort.c
More file actions
59 lines (48 loc) · 1016 Bytes
/
Copy pathquickSort.c
File metadata and controls
59 lines (48 loc) · 1016 Bytes
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
// Online C compiler to run C program online
#include <stdio.h>
#include<stdlib.h>
int partition(int A[],int low,int high){
int pivot=A[low];
int temp;
int i =low+1;
int j =high;
do{
while(A[i]<=pivot){
i++;
}
while(A[j]>pivot){
j++;
}
if(i<j){
temp=A[i];
A[i]=A[j];
A[j]=temp;
}
}
while(i<j);
temp=A[low];
A[low]=A[j];
A[j]=temp;
}
void quickSort(int A[] , int low , int high ){
int partitionIndex; //index of pivot after partition
if(low<high){
partitionIndex = partition(A,low,high);
quickSort(A,low,partitionIndex-1);
quickSort(A,partitionIndex+1,high);
}
printf("Sorted!");
}
void display(int A[],int n){
int i;
for(i=0;i<n;i++){
printf("%d",A[i]);
}
}
int main() {
// Write C code here
int A[5]={2,5,8,1,3};
quickSort(A,0,1);
display(A,5);
return 0;
}