forked from heqin-zhu/algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquickSort.c
More file actions
31 lines (31 loc) · 768 Bytes
/
quickSort.c
File metadata and controls
31 lines (31 loc) · 768 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
/* mbinary
#########################################################################
# File : quickSort.c
# Author: mbinary
# Mail: [email protected]
# Blog: https://mbinary.xyz
# Github: https://github.com/mbinary
# Created Time: 2019-04-16 09:41
# Description:
#########################################################################
*/
int partition(int *arr,int i,int j)
{
int pivot = arr[j],p=i,q=j;
while(p<q){
while(p<q && arr[p]<=pivot)++p;
if(p<q)arr[q--]=arr[p];
while(p<q && arr[q]>pivot)--q;
if(p<q)arr[p++]=arr[q];
}
arr[p]=pivot;
return p;
}
void quickSort(int *arr,int i,int j)
{
if(i<j){
int p = partition(arr,i,j);
quickSort(arr,i,p-1);
quickSort(arr,p+1,j);
}
}