-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLab#09__Farhanulhaq_Task#1.cpp
More file actions
92 lines (76 loc) · 1.91 KB
/
Copy pathLab#09__Farhanulhaq_Task#1.cpp
File metadata and controls
92 lines (76 loc) · 1.91 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
87
88
89
90
91
92
#include <iostream>
#include <string>
using namespace std;
class Person {
private:
int per_id;
string per_name;
int per_age;
public:
Person() : per_id(0), per_name(""), per_age(0) {}
void input() {
cout << "Enter Person ID: ";
cin >> per_id;
cout << "Enter Name: ";
cin.ignore();
getline(cin, per_name);
cout << "Enter Age: ";
cin >> per_age;
}
void output() const {
cout << "ID: " << per_id << ", Name: " << per_name << ", Age: " << per_age << endl;
}
};
struct Node {
Person person;
Node* next;
};
class Queue {
private:
Node* front;
Node* rear;
public:
Queue() : front(nullptr), rear(nullptr) {}
void addQueue() {
Node* newNode = new Node();
newNode->person.input();
newNode->next = nullptr;
if (rear == nullptr) {
front = rear = newNode;
} else {
rear->next = newNode;
rear = newNode;
}
}
void removeQueue() {
if (front == nullptr) {
cout << "Queue is empty!" << endl;
return;
}
Node* temp = front;
front = front->next;
if (front == nullptr) {
rear = nullptr;
}
temp->person.output();
delete temp;
}
bool isEmpty() const {
return front == nullptr;
}
};
int main() {
Queue queue;
int choice;
do {
cout << "1. Add Person to Queue\n2. Remove Person from Queue\n3. Exit\nEnter choice: ";
cin >> choice;
switch (choice) {
case 1: queue.addQueue(); break;
case 2: queue.removeQueue(); break;
case 3: cout << "Exiting..." << endl; break;
default: cout << "Invalid choice!" << endl;
}
} while (choice != 3);
return 0;
}