-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudent_Quick.cpp
More file actions
50 lines (45 loc) · 1014 Bytes
/
Student_Quick.cpp
File metadata and controls
50 lines (45 loc) · 1014 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
49
50
#include <iostream>
using namespace std;
int partition(float x[100], int lb, int ub) {
float a, temp;
int down, up;
a = x[lb];
down = lb;
up = ub;
while (down < up) {
while (x[down] <= a && down < up)
down++;
while (x[up] > a)
up--;
if (down < up) {
temp = x[down];
x[down] = x[up];
x[up] = temp;
}
}
x[lb] = x[up];
x[up] = a;
return up;
}
void quicksort(float x[100], int lb, int ub) {
int j;
if (lb < ub) {
j = partition(x, lb, ub);
quicksort(x, lb, j - 1);
quicksort(x, j + 1, ub);
}
}
int main() {
float arr[100];
int i, n;
cout << "\nEnter number of students: ";
cin >> n;
cout << "\nEnter " << n << " student:\n";
for (i = 0; i < n; i++)
cin >> arr[i];
quicksort(arr, 0, n - 1);
cout << "\nAfter sort, students are: ";
for (i = 0; i < n; i++)
cout << arr[i] << "\t";
return 0;
}