bai2
bai2
#include <list>
#include <string>
struct SinhVien {
int id;
string ten;
};
class Queue {
private:
list<SinhVien> data;
public:
void enqueue(SinhVien sv) {
data.push_back(sv);
}
void dequeue() {
if (isEmpty()) {
cout << "Hàng d?i tr?ng!" << endl;
return;
}
data.pop_front();
}
bool isEmpty() {
return data.empty();
}
void printQueue() {
if (isEmpty()) {
cout << "Hàng d?i tr?ng!" << endl;
return;
}
int main() {
Queue queue;
int choice, n, id;
string ten;
do {
cout << "\nMenu:" << endl;
cout << "1. Thêm sinh viên" << endl;
cout << "2. Xóa sinh viên" << endl;
cout << "3. In danh sách sinh viên" << endl;
cout << "4. Thoát" << endl;
cout << "Ch?n ch?c nang: ";
cin >> choice;
switch (choice) {
case 1:
cout << "Nh?p s? lu?ng sinh viên mu?n thêm: ";
cin >> n;
for (int i = 0; i < n; ++i) {
cout << "Nh?p ID sinh viên th? " << i + 1 << ": ";
cin >> id;
cout << "Nh?p tên sinh viên th? " << i + 1 << ": ";
cin >> ten;
SinhVien sv = {id, ten};
queue.enqueue(sv);
}
break;
case 2:
queue.dequeue();
break;
case 3:
queue.printQueue();
break;
case 4:
break;
default:
cout << "L?a ch?n không h?p l?!" << endl;
}
} while (choice != 4);
return 0;
}