-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinked_list.cpp
More file actions
149 lines (116 loc) · 4.89 KB
/
linked_list.cpp
File metadata and controls
149 lines (116 loc) · 4.89 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#include "linked_list.hpp"
#include "passenger.hpp"
// kaemon
void reserveSeatLinkedList(Passenger p) {
auto start = high_resolution_clock::now();
Passenger* newNode = new Passenger;
*newNode = p;
newNode->next = head;
head = newNode;
auto stop = high_resolution_clock::now();
double timeTaken = duration_cast<duration<double, micro>>(stop - start).count();
cout << "\n>>> [LINKED LIST IMPLEMENTATION RESULTS] <<<\n";
cout << "Status: SUCCESS\n";
cout << left << setw(20) << " ~ Time Taken: " << fixed << setprecision(2) << timeTaken << " microseconds" << endl;
spaceTrack("list");
}
// hao
void cancelSeatLinkedList(int targetID){
auto start = high_resolution_clock::now();
Passenger* current = head;
Passenger* prev = nullptr;
bool found = false;
Passenger removedInfo;
// Search Logic
while (current != nullptr) {
if (current->id == targetID) {
removedInfo.name = current->name;
removedInfo.seatRow = current->seatRow;
removedInfo.seatColumn = current->seatColumn;
removedInfo.planeNo = current->planeNo;
// DELETE
if (prev == nullptr) {
head = current->next;
} else {
prev->next = current->next;
}
delete current;
found = true;
break;
}
prev = current;
current = current->next;
}
auto stop = high_resolution_clock::now();
double timeTaken = duration_cast<duration<double, micro>>(stop - start).count();
// OUTPUT
cout << "\n>>> [LINKED LIST IMPLEMENTATION RESULTS] <<<\n";
if (found) {
cout << "Status: SUCCESS\n";
cout << "Passenger: " << removedInfo.name << " (ID: " << targetID << ")\n";
cout << "Flight Info: Plane " << removedInfo.planeNo << " | Seat " << removedInfo.seatRow << removedInfo.seatColumn << "\n";
} else {
cout << "Status: FAILED (ID Not Found)\n";
}
cout << left << setw(20) << " ~ Time Taken: " << fixed << setprecision(2) << timeTaken << " microseconds" << endl;
spaceTrack("list");
};
// rijesh
void searchSeatLinkedList(int targetID){
auto start = high_resolution_clock::now();
bool found = false;
Passenger* current = head;
Passenger* foundNode = nullptr;
while (current != nullptr) {
if (current->id == targetID) {
foundNode = current;
found = true;
break;
}
current = current->next;
}
auto stop = high_resolution_clock::now();
double timeTaken = duration_cast<duration<double, micro>>(stop - start).count();
cout << "\n>>> [LINKED LIST IMPLEMENTATION RESULTS] <<<\n";
if (found) {
cout << "Status: SUCCESS\n";
cout << "Passenger: " << foundNode->name << " (ID: " << foundNode->id << ")\n";
cout << "Flight Info: Plane " << foundNode->planeNo
<< " | Seat " << (to_string(foundNode->seatRow) + foundNode->seatColumn) << "\n";
cout << "Class: " << foundNode->flightClass << "\n";
} else {
cout << "Status: FAILED (ID Not Found)\n";
}
cout << left << setw(20) << " ~ Time Taken: " << fixed << setprecision(2) << timeTaken << " microseconds" << endl;
spaceTrack("list");
};
// quan
void seatReporLinkedList(){
auto start = high_resolution_clock::now();
cout << "\n--------------- LINKED LIST REPORT ---------------" << endl;
cout << left << setw(10) << "Plane" << setw(12) << "ID" << setw(20) << "Name" << setw(10) << "Seat" << "Class" << endl;
cout << "---------------------------------------------------------" << endl;
int count = 0;
Passenger* current = head;
// 1. Traverse the list until the end
while (current != nullptr) {
cout << left
<< setw(10) << current->planeNo
<< setw(12) << current->id
<< setw(20) << current->name.substr(0, 19)
<< setw(10) << (to_string(current->seatRow) + current->seatColumn)
<< current->flightClass << endl;
count++;
current = current->next; // Move to next node
}
if (count == 0) cout << "No passengers found." << endl;
auto stop = high_resolution_clock::now();
cout << "--------------------------------------------------------------" << endl;
cout << " > Total Loaded Nodes: " << count << "\n";
double timeTaken = duration_cast<duration<double, micro>>(stop - start).count();
cout << "--------------------------------------------------------------" << endl;
cout << " >>> [Linked List Seat Report Performance] <<<" << endl;
cout << "--------------------------------------------------------------" << endl;
cout << left << setw(20) << " ~ Time Taken: " << fixed << setprecision(2) << timeTaken << " microseconds" << endl;
spaceTrack("list");
};