-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkedListManagement.cpp
More file actions
84 lines (77 loc) · 2.06 KB
/
Copy pathLinkedListManagement.cpp
File metadata and controls
84 lines (77 loc) · 2.06 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
#include "LinkedListManagement.h"
#include <iostream>
LinkedListManagement::LinkedListManagement() {
root_node = nullptr;
}
LinkedListManagement::~LinkedListManagement() {
if (list_info.IsEmptyList(root_node)) {
std::cout << "List is empty.";
return;
}
struct Node* current_node = root_node->prev_node;
while (current_node != root_node) {
struct Node* temp_ptr = current_node;
current_node = current_node->prev_node;
delete temp_ptr;
}
delete root_node;
root_node = nullptr;
}
void LinkedListManagement::InsertNode() {
root_node = insert.InsertNode(root_node, node);
}
void LinkedListManagement::DeleteNode() {
root_node = remove.DeleteNode(root_node, node);
}
void LinkedListManagement::PrintList() {
if (list_info.IsEmptyList(root_node)) {
std::cout << "List is empty.";
return;
}
struct Node* current_node = root_node;
do {
std::cout << current_node->data << "<-->";
current_node = current_node->next_node;
} while (current_node->next_node != root_node);
std::cout << current_node->data << "<-->" << root_node->data << "\n";
}
void LinkedListManagement::PrintMenu() {
std::cout << "\nWelcome to Linked List Management System.\n";
std::cout << "1. Insert\n";
std::cout << "2. Delete\n";
std::cout << "3. List Nodes\n";
std::cout << "4. Exit\n";
std::cout << "Selection >> ";
}
void LinkedListManagement::LaunchLinkedListManagement() {
int selection{0};
do {
PrintMenu();
selection = request.GetValidatedUserInput(selection);
switch (selection) {
case 1: {
node = request.InsertRequest(root_node);
InsertNode();
break;
}
case 2: {
node = request.DeleteRequest(root_node);
DeleteNode();
break;
}
case 3: {
std::cout << "\nLIST ALL NODES: \n----------------\n";
PrintList();
break;
}
case 4: {
std::cout << "\nThank you... Goodbye!\n";
break;
}
default: {
std::cout << "Invalid selection. Try again\n";
break;
}
}
} while (selection != 4);
}