forked from Dipak3007/Hacktoberfest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuickSort.c
More file actions
41 lines (38 loc) · 754 Bytes
/
QuickSort.c
File metadata and controls
41 lines (38 loc) · 754 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
#include<stdio.h>
int Partition(int A[],int p,int r){
int x=A[r],i=p-1,temp;
for(int j=p;j<r;j++){
if(A[j]<=x){
i++;
temp=A[i];
A[i]=A[j];
A[j]=temp;
}
}
temp=A[i+1];
A[i+1]=A[r];
A[r]=temp;
return i+1;
}
void QuickSort(int A[],int p,int r){
if(p<r){
int q=Partition(A,p,r);
QuickSort(A,p,q-1);
QuickSort(A,q+1,r);
}
}
int main()
{
int n;
printf("Enter size of array : ");
scanf("%d",&n);
int A[n];
printf("Enter Array :-\n");
for(int i=0;i<n;i++)
scanf("%d",&A[i]);
QuickSort(A,0,n-1);
printf("\nSorted Array :-\n");
for(int i=0;i<n;i++)
printf("%d ",A[i]);
return 0;
}