-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.cpp
91 lines (86 loc) · 2.69 KB
/
Main.cpp
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
//-----------------------------------------------------------
// CS 215 – Spring 2018
// Project 4
//-----------------------------------------------------------
// Author: <Blair Hall>
// Section: <004>
// Description:Implementation of a dynamic list data structure
// Assistance: I received help from the following:
// Thomas Barber
//-----------------------------------------------------------
#include <iostream>
#include "LList.h"
//-----------------------------------------------------------
// askAction
//-----------------------------------------------------------
char askAction() {
string userinput;
cout << "\nTEST MENU:\n";
cout << "I - Insert\n";
cout << "D - Delete (Drop)\n";
cout << "P - Print List\n";
cout << "F - Find\n";
cout << "S - Sort\n";
cout << "X - Exit\n";
cout << "==> ";
if (cin.peek() == '\n') cin.ignore();
getline(cin, userinput);
return toupper(userinput[0]);
} // askAction()
//-----------------------------------------------------------
// testInsert
//-----------------------------------------------------------
void testInsert(LList & L) {
int key;
string data;
cout << "Enter key: ";
cin >> key;
cout << "Enter data: ";
cin.ignore();
getline(cin, data);
L.insert(key, data);
} // testInsert()
//-----------------------------------------------------------
// testDrop
//-----------------------------------------------------------
void testDrop(LList & L) {
int key;
cout << "Enter key: ";
cin >> key;
if (L.drop(key))
cout << key << " removed\n";
else
cout << key << " not found in list\n";
} // testDrop()
//-----------------------------------------------------------
// testFind
//-----------------------------------------------------------
void testFind(LList & L) {
int key;
cout << "Enter key: ";
cin >> key;
L.findNode(key);
} // testFind()
//-----------------------------------------------------------
// main()
//-----------------------------------------------------------
int main() {
{ // extra block included to view destruction of L
LList L;
char action = ' ';
while (action != 'X') {
action = askAction();
switch (action) {
case 'I': testInsert(L); break;
case 'D': testDrop(L); break;
case 'F': testFind(L); break;
case 'P': L.print(); break;
case 'S': L.sort(); cout << "Sorted\n"; break;
case 'X': cout << "Exiting...\n"; break;
default: cout << "Invalid option\n";
}
}
} // L will be destoyed upon exit of this block
system("pause");
return 0;
} // main()