-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
55 lines (52 loc) · 1.01 KB
/
main.c
File metadata and controls
55 lines (52 loc) · 1.01 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
47
48
49
50
51
52
53
54
55
#include <stdio.h>
#include <string.h>
#define swap(x,y,t) ((t)=(x), (x)=(y), (y)=(t))
int list[100];
int p(int list[], int left,int right)
{
int pivot,temp,low,high;
low = left;
high= right+1;
pivot=list[left];
do
{
do
{
low++;
}while(list[low]<pivot && low<=right);
do
{
high--;
}while(list[high]>pivot);
if(low<high)
{
swap(list[low],list[high],temp);
}
}while(low<high);
swap(list[left],list[high],temp);
return high;
}
void q(int list[], int left,int right)
{
if(left<right)
{
int a=p(list, left, right);
q(list,left,a-1);
q(list,a+1,right);
}
}
int main()
{
int n, i, lenght=0;
scanf("%d", &n);
for(i=0;i<n;i++){
scanf("%d", &list[i]);
}
for(i=0;list[i]!=0;i++) lenght++;
q(list,0,lenght-1);
for(i=0; i<n; i++)
{
printf("%d ",list[i]);
}
return 0;
}