- Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathquicksort.cpp
More file actions
Latest commit
41 lines (40 loc) · 591 Bytes
/
Copy pathquicksort.cpp
File metadata and controls
41 lines (40 loc) · 591 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
#include<bits/stdc++.h>
usingnamespacestd;
intpartition(int low,int high,int a[])
{
int i,j,x=a[high];
i=low-1;
for(j=low;j<high;j++)
{
if(a[j]<=x)
{
i+=1;
swap(a[i],a[j]);
}
}
swap(a[i+1],a[high]);
return i+1;
}
voidquicksort(int low,int high,int a[])
{
if(low<high)
{
int pivot=partition(low,high,a);
quicksort(low,pivot-1,a);
quicksort(pivot+1,high,a);
}
}
intmain()
{
int n,i,a[100000];
cin>>n;
for(i=0;i<n;i++)
{
cin>>a[i];
}
quicksort(0,n-1,a);
for(i=0;i<n;i++)
{
cout<<a[i]<<"";
}
}