-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquick.c
46 lines (45 loc) · 861 Bytes
/
quick.c
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>
#include<stdlib.h>
int partition(int a[100], int f, int l)
{
int i,p,j,temp;
p = a[l];
j = f;
for(i=f; i< l ;i++)
{
if(a[i] <= p)
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
j++;
}
}
temp = a[j];
a[j] = a[l];
a[l] = temp;
return j;
}
void quicksort(int a[100], int f, int l)
{
int j,i;
if(i<l)
{
j = partition(a,f,l);
quicksort(a,f,j-1);
quicksort(a,j+1,l);
}
}
void main()
{
int a[100],i,n,f,l;
printf("Enter size\n");
scanf("%d",&n);
printf("\nEnter elements \t");
for(i=0;i<n;i++)
scanf("%d",a[i]);
quicksort(a,0,n-1);
printf("Sorted list is : ");
for(i=0;i<n;i++)
printf("%d\t",a[i]);
}