forked from Shubhamlmp/Programming-Practice
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuickSort.cpp
More file actions
68 lines (68 loc) · 1.18 KB
/
Copy pathQuickSort.cpp
File metadata and controls
68 lines (68 loc) · 1.18 KB
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;
static int count=0;
int Partition(int a[],int low,int high)
{
int i=low+1,j=high;
int pivot=a[low];
do
{
while(a[i]<=pivot)
{
i++;
count++;
}
while(a[j]>pivot)
{
j--;
count++;
}
if(i<j)
{
int temp=a[i];
a[i]=a[j];
a[j]=temp;
count++;
}
count++;
}while(i<j);
count++;
int temp=a[low];
a[low]=a[j];
a[j]=temp;
return j;
}
void Quicksort(int a[],int low,int high)
{
if(low<high)
{
int mid=Partition(a,low,high);
Quicksort(a,low,mid-1);
Quicksort(a,mid+1,high);
}
}
int main() {
int n;
cout<<"Enter number of players:";
cin>>n;
int a[n],low=0,high=n-1;
cout<<"Enter the player's rating:";
for(int i=0;i<n;i++)
{
cin>>a[i];
//a[i]=rand()%100;
}
Quicksort(a,low,high);
cout<<"Team1:\n";
for(int i=0;i<n/2;i++)
{
cout<<a[i]<<" ";
}
cout<<"\nTeam2:\n";
for(int i=n/2;i<n;i++)
{
cout<<a[i]<<" ";
}
cout<<"\nNo of comparisons:"<<count;
return 0;
}