-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignment 13.cpp
More file actions
86 lines (85 loc) · 1.33 KB
/
Assignment 13.cpp
File metadata and controls
86 lines (85 loc) · 1.33 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//============================================================================
// Name : Assignment 13.cpp
// Author : 21258
// Version :
// Copyright : Your copyright notice
// Description : Quicksort
//============================================================================
#include <iostream>
using namespace std;
class student
{
public:
float a[100];
int n;
int partition(int low, int high)
{
float pivot=a[high],t;
int i=low;
int j=high;
while(i<j)
{
while(a[i]<=pivot&&i<high)
i++;
while(a[j]>=pivot&&j>low)
j--;
if(i<j)
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
t=a[high];
a[high]=a[i];
a[i]=t;
return i;
}
void quickSort(int low, int high)
{
if(low<high)
{
int p=partition(low,high);
quickSort(low,p-1);
quickSort(p+1,high);
}
}
void input()
{
cout<<"Enter the number of students: ";
cin>>n;
for(int i=0;i<n;i++)
{
cout<<"Enter percentage of student "<<i+1<<": ";
cin>>a[i];
}
}
void output()
{
for(int i=0;i<n;i++)
{
cout<<a[i]<<" ";
}
cout<<endl;
}
void top5()
{
for(int i=n-1;i>n-6;i--)
{
cout<<a[i]<<" ";
}
cout<<endl;
}
};
int main() {
student s;
s.input();
cout<<"Unsorted list: \n";
s.output();
s.quickSort(0,s.n-1);
cout<<"Sorted list: \n";
s.output();
cout<<"Top 5: \n";
s.top5();
return 0;
}