forked from Rishu1018/HackertoberFest2022-Repostory_Newbie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuicksort.cpp
41 lines (41 loc) · 841 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
#include<iostream>
using namespace std;
void print(int * arr,int n)
{
for(int i =0;i<n;i++)
{
cout<<arr[i]<<" , ";
}
cout<<endl;
}
void quick(int * arr,int start,int end)
{
if(start<end)
{
int i = start-1;
int p = arr[end];
for(int j = start;j<end;j++)
{
if(arr[j]<p)
{
i++;
swap(arr[i],arr[j]);
}
}
i++;
swap(arr[i],arr[end]);
// print(arr,end-start);
// cout<<"------------------------------------------------------------"<<endl;
quick(arr,start,i-1);
quick(arr,i+1,end);
}
}
int main()
{
int arr[]={5,4,3,2,1,-1,-100};
int n = sizeof(arr)/sizeof(int);
int start = 0;
int end = n-1;
quick(arr,start,end);
print(arr,n);
}