-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlgorithm.c
More file actions
49 lines (46 loc) · 905 Bytes
/
Algorithm.c
File metadata and controls
49 lines (46 loc) · 905 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
#include <stdio.h>
#define swap(x,y,t) ((t)=(x), (x)=(y), (y)=(t))
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 list[6]={32,17,4,52,29,45};
q(list,0,5);
int i;
for(i=0; i<6; i++)
{
printf("%d ",list[i]);
}
return 0;
}