-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuickSort.cpp
68 lines (62 loc) · 1.39 KB
/
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include<iostream>
using namespace std;
class Suvrodev
{
public:
int temp;
void quicksort(int*,int,int);
};
void Suvrodev::quicksort(int* Data,int begin, int end)
{
int Pivot,Left,Right;
if(begin<end)
{
Pivot=begin;
Left=begin;
Right=end;
while(Left<Right)
{
while(Data[Left]<=Data[Pivot] && Left<end)
{
Left++;
}
while(Data[Right]>Data[Pivot])
{
Right--;
}
if(Left<Right)
{
temp=Data[Left];
Data[Left]=Data[Right];
Data[Right]=temp;
}
}
temp=Data[Right];
Data[Right]=Data[Pivot];
Data[Pivot]=temp;
quicksort(Data,begin,Right-1);
quicksort(Data,Right+1,end);
}
}
int main()
{
cout<<"Quick Sort"<<endl;
Suvrodev v;
int Limit,begin=1;
cout<<"Enter the Limit of Array:";
cin>>Limit;
int Data[Limit];
cout<<"Enter Element from here"<<endl;
for(int i=begin;i<=Limit;i++)
{
cout<<i<<". Enter Input:";
cin>>Data[i];
}
v.quicksort(Data,begin,Limit);
cout<<"Sorted Element:";
for(int i=begin;i<=Limit;i++)
{
cout<<Data[i]<<" ";
}
return 0;
}