forked from WebClub-NITK/Hacktoberfest-2k17
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquicksort.cpp
More file actions
49 lines (44 loc) · 757 Bytes
/
Copy pathquicksort.cpp
File metadata and controls
49 lines (44 loc) · 757 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
#include<bits/stdc++.h>
using namespace std;
int partition1(int a[],int l,int r)
{
int temp,i;
int pivot=a[r];
int p=l;
for(i=l;i<r;i++)
{
if(a[i]<=pivot)
{
//swap(a[i],a[p])
temp=a[i];
a[i]=a[p];
a[p]=temp;
p++;
}
}
//swap(a[p],pivot);
temp=a[p];
a[p]=a[r];
a[r]=temp;
return p;
}
void quicksort(int a[],int l,int r)
{
if(l>=r)
return;
int p=partition1(a,l,r);
quicksort(a,l,p-1);
quicksort(a,p+1,r);
}
int main()
{
int i,j,k,l,m,n;
scanf("%d",&n);
int a[n];
for(i=0;i<n;i++)
scanf("%d",&a[i]);
quicksort(a,0,n-1);
for(i=0;i<n;i++)
printf("%d ",a[i]);
return 0;
}