-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkedListDemo.cpp
More file actions
102 lines (84 loc) · 3 KB
/
Copy pathLinkedListDemo.cpp
File metadata and controls
102 lines (84 loc) · 3 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
// LinkedListDemo - Main Program
/******************************/
// Author: SENG1120 Staff
// Course: SENG1120
// Program Description: This program demonstrates the basic functionality of a linked list that stores student names
// and scores. It will demo the functions of a basic linked list.
// The program adds content to a linked list, removes individual nodes, among other functionalities.
#include <iostream>
#include <cstdlib>
#include "LinkedList.h"
#include "Student.h"
using namespace std;
void initialize(LinkedList &l1, LinkedList &l2)
{
Student c("Alex", 45);
l1.addToTail(c);
c.set_name("Peter"); c.set_score(10);
l1.addToTail(c);
c.set_name("John"); c.set_score(32);
l1.addToTail(c);
c.set_name("Mary"); c.set_score(95);
l1.addToTail(c);
c.set_name("Karen"); c.set_score(70);
l1.addToTail(c);
c.set_name("Carol"); c.set_score(31);
l1.addToTail(c);
c.set_name("Michelle"); c.set_score(12);
l2.addToTail(c);
c.set_name("Carol"); c.set_score(27);
l2.addToTail(c);
c.set_name("Tim"); c.set_score(20);
l2.addToTail(c);
c.set_name("John"); c.set_score(75);
l2.addToTail(c);
c.set_name("Tony"); c.set_score(60);
l2.addToTail(c);
c.set_name("Chris"); c.set_score(85);
l2.addToTail(c);
c.set_name("Michelle"); c.set_score(90);
l2.addToTail(c);
}
int main()
{
LinkedList firstList;
LinkedList secondList;
initialize(firstList, secondList);
cout << "Start lists:" << endl;
cout << "List 1: " << firstList << endl;
cout << "List 2: " << secondList << endl << endl;
cout << "Concatenating the two lists onto list '1':" << endl;
firstList += secondList;
cout << "List 1: " << firstList << endl;
cout << "List 2: " << secondList << endl << endl;
cout << "Removing student 'Alex' from list '1':" << endl;
firstList.remove("Alex");
cout << "List 1: " << firstList << endl;
cout << "List 2: " << secondList << endl << endl;
cout << "Removing student 'John' from list '2':" << endl;
secondList.remove("John");
cout << "List 1: " << firstList << endl;
cout << "List 2: " << secondList << endl << endl;
cout << "Removing all ocurrences of 'Michelle' from both lists:" << endl;
firstList.remove("Michelle");
secondList.remove("Michelle");
cout << "List 1: " << firstList << endl;
cout << "List 2: " << secondList << endl << endl;
cout << "Removing student 'Fred' from list '2':" << endl;
secondList.remove("Fred");
cout << "List 1: " << firstList << endl;
cout << "List 2: " << secondList << endl << endl;
cout << "Statistics of list '1': ";
firstList.printStatistics();
cout << "Statistics of list '2': ";
secondList.printStatistics();
cout << endl << "Number of students named 'Carol': ";
cout << (firstList.count("Carol") + secondList.count("Carol")) << endl << endl;
cout << "Ordered lists: " << endl;
firstList.order();
secondList.order();
cout << "List 1: " << firstList << endl;
cout << "List 2: " << secondList << endl << endl;
cout << "The program has finished." << endl;
return 0;
}