forked from apanangadan/CSUF-CPSC_131
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathNodeList_main.cpp
More file actions
49 lines (41 loc) · 967 Bytes
/
NodeList_main.cpp
File metadata and controls
49 lines (41 loc) · 967 Bytes
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
#include <stdexcept>
#include <iostream>
#include <string>
#include "NodeList.h" // doubly linked list with iterators
using namespace std;
class Student {
private:
string _name;
int _nsemesters;
public:
void print() {
cout << "Name:" << _name << "; No. of semesters=" << _nsemesters << endl;
}
void setName(string name) {
_name = name;
}
void setNSemesters(int n) {
_nsemesters = n;
}
void updateNSemesters() {
_nsemesters++;
}
};
int main() {
NodeList<Student> students;
Student s;
for (int i = 0; i < 5; i++) {
s.setName("Student_" + to_string(i));
s.setNSemesters(2);
students.insertFront(s);
}
for (int i = 0; i < 5; i++) {
s.setName("Student_" + to_string(i+50));
s.setNSemesters(2);
students.insertBack(s); // can also insert at the end
}
for (NodeList<Student>::Iterator i = students.begin(); i != students.end(); ++i) {
i.get().print();
}
// system("pause");
}