Quicksort
Quicksort
Quicksort
cpp Page 1 of 2
#include <iostream>
#include <string>
using namespace std;
struct student {
int roll_no;
string name;
float SGPA;
};
// ACCEPT FUNCTION
void accept(student list[arraySize]) {
for (int i = 0; i < arraySize; i++) {
cout << "\nEnter Roll-Number, Name, SGPA: ";
cin >> list[i].roll_no >> list[i].name >> list[i].SGPA;
}
}
// DISPLAY FUNCTION
void display(const student list[], int size) {
cout << "\nRoll-Number \t Name \t SGPA\n";
for (int i = 0; i < size; i++) {
cout << list[i].roll_no << " \t " << list[i].name << "\t " << list[i].SGPA << endl;
}
}
int main() {
int ch;
student data[arraySize];
accept(data);
do {
cout << "\n1) Quick Sort";
cout << "\n2) Exit";
File: quicksort.cpp Page 2 of 2
switch (ch) {
case 1:
quick_sort(data, 0, arraySize - 1);
// Display top 10 or less if there are fewer than 10 students
cout << "\nTop Students:\n";
display(data, min(10, arraySize));
break;
case 2:
cout << "\nYou Have Successfully Exited!!!.";
break;
default:
cout << "\nPlease Enter Valid Choice.\n";
}
} while (ch != 2);
return 0;
}