forked from 2015jamrajput/programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuicksort.c
More file actions
46 lines (46 loc) · 1.02 KB
/
Quicksort.c
File metadata and controls
46 lines (46 loc) · 1.02 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 arr[],int low,int high){
int pivot=arr[low];
int i=low+1;
int j=high;
do{
while(arr[i]<=pivot){
i++;
}
while(arr[j]>pivot){
j--;
}
if(i<j){
int temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}while(i<j);
int temp=arr[low];
arr[low]=arr[j];
arr[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 Array length:-\n");
scanf("%d",&n);
int arr[n];
printf("Enter 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]);
}
}