-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
116 lines (89 loc) · 2.32 KB
/
Copy pathmain.cpp
File metadata and controls
116 lines (89 loc) · 2.32 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
#include <iostream>
#include "LinkedList.h"
#include "LinkedList.cpp"
#include <string>
using namespace std;
void ShowListOFPrimitiveType(Node<int> *list)
{
while (list != NULL)
{
cout << list->data << endl;
list = list->next;
}
}
void PrimitiveTypeExample()
{
LinkedList<int> newList;
// Add Elements
newList.Add(5);
newList.Add(10);
newList.Add(11);
newList.Add(12);
cout << "Items added" << endl;
// Get list first item
Node<int> *head = newList.GetList();
// Show list elements
ShowListOFPrimitiveType(head);
newList.Add(70);
// Remove elements
newList.Remove(5);
cout << "Item value 5 removed!" << endl;
cout << "------------" << endl;
ShowListOFPrimitiveType(head);
}
struct Student
{
int number;
string name;
string surname;
string className;
bool operator==(const Student &other) const
{
return number == other.number && name == other.name && surname == other.surname && className == other.className;
}
};
void ShowListOfStruct(Node<Student> *list)
{
while (list != NULL)
{
cout << "Student Number: " << list->data.number << endl;
cout << "Student Name: " << list->data.name << endl;
cout << "Student Surname: " << list->data.surname << endl;
cout << "Student Class Name: " << list->data.className << endl;
list = list->next;
}
}
void StructExample()
{
// Create List
LinkedList<Student> studentList;
// Create new student
Student newStudentOne;
newStudentOne.number = 5;
newStudentOne.name = "John";
newStudentOne.surname = "Doe";
newStudentOne.className = "6A";
// Add student item to list list
studentList.Add(newStudentOne);
// Create new student
Student newStudentTwo;
newStudentTwo.number = 10;
newStudentTwo.name = "Jane";
newStudentTwo.surname = "Doe";
newStudentTwo.className = "6A";
studentList.Add(newStudentTwo);
cout << "Items added" << endl;
Node<Student> *head = studentList.GetList();
ShowListOfStruct(head);
// Remove elements
studentList.Remove(newStudentOne);
cout << "Item student one removed!" << endl;
cout << "------------" << endl;
ShowListOfStruct(head);
}
int main()
{
PrimitiveTypeExample();
StructExample();
return 0;
}