-
Notifications
You must be signed in to change notification settings - Fork 0
/
QuickSort.cpp
50 lines (42 loc) · 1015 Bytes
/
QuickSort.cpp
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
#include <stdio.h>
#include <stdlib.h>
#define N 6
int partition(int arr[], int low, int high){
int key;
key = arr[low];
while(low<high){
while(low <high && arr[high]>= key )
high--;
if(low<high)
arr[low++] = arr[high];
while( low<high && arr[low]<=key )
low++;
if(low<high)
arr[high--] = arr[low];
}
arr[low] = key;
return low;
}
void quick_sort(int arr[], int start, int end){
int pos;
if (start<end){
pos = partition(arr, start, end);
quick_sort(arr,start,pos-1);
quick_sort(arr,pos+1,end);
}
return;
}
int main(void){
int i;
int arr[N]={32,12,7, 78, 23,45};
printf("ÅÅÐòÇ° \n");
for(i=0;i<N;i++)
printf("%d\t",arr[i]);
quick_sort(arr,0,N-1);
printf("\n ÅÅÐòºó \n");
for(i=0; i<N; i++)
printf("%d\t", arr[i]);
printf ("\n");
system("pause");
return 0;
}