-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuick_sort.c
More file actions
54 lines (53 loc) · 816 Bytes
/
Quick_sort.c
File metadata and controls
54 lines (53 loc) · 816 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
#include<stdio.h>
void quick(int *,int,int);//Base Address, lowest index, Highest Index
int main()
{
int i,n;
printf("How many numbers ");
scanf("%d",&n);
int a[n];
printf("Enter %d numbers ",n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
quick(a,0,n-1);
printf("The numbers in ascending order are ");
for(i=0;i<n;i++ )
printf("%d ",a[i]);
return 0;
}
void quick(int a[],int low,int up)
{
int l,r,p,t;
l=low;
r=up;
p=low;
if(low>=up)
return;
while(1)
{
while(a[r]>=a[p] && p!=r)
r--;
if(p==r)
break;
if(a[r]<a[p])
{
t=a[p];
a[p]=a[r];
a[r]=t;
p=r;
}
while(a[l]<=a[p] && l!=p)
l++;
if(p==l)
break;
if(a[l]>a[p])
{
t=a[p];
a[p]=a[l];
a[l]=t;
p=l;
}
}
quick(a,low,p-1);
quick(a,p+1,up);
}