forked from 2015jamrajput/Basic_C_codes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquick.c
More file actions
46 lines (46 loc) · 1.05 KB
/
quick.c
File metadata and controls
46 lines (46 loc) · 1.05 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
#include<stdio.h>
int partion(int part[],int low,int high){
int pivot=part[low];
int i=low+1;
int j=high;
do{
while(part[i]<=pivot){
i++;
}
while(part[j]>pivot){
j--;
}
if(i<j){
int temp=part[i];
part[i]=part[j];
part[j]=temp;
}
}while(i<j);
int temp=part[low];
part[low]=part[j];
part[j]=temp;
return j;
}
void quicksort(int sort[],int low,int high){
int partionPoint;
if(low<high){
partionPoint = partion(sort,low,high);
quicksort(sort,low,partionPoint-1);
quicksort(sort,partionPoint+1,high);
}
}
int main(){
int n;
printf("Enter the length of Array:-\n");
scanf("%d",&n);
int arr[n];
printf("Enter your Array elements:-\n");
for(int i=0;i<n;i++){
scanf("%d",&arr[i]);
}
quicksort(arr,0,n-1);
printf("Your Sorted Array is:-\n");
for(int i=0;i<n;i++){
printf("%d ",arr[i]);
}
}