-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinkedlist.cpp
More file actions
57 lines (45 loc) · 900 Bytes
/
linkedlist.cpp
File metadata and controls
57 lines (45 loc) · 900 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
50
51
52
53
54
55
56
57
#include <iostream>
using namespace std;
class IntNode {
public:
IntNode(int value) {
numVal = value;
}
~IntNode() {
cout << numVal << endl;
}
int numVal;
IntNode* next;
};
class IntLinkedList {
public:
IntLinkedList();
~IntLinkedList();
void Prepend(int);
IntNode* head;
};
IntLinkedList::IntLinkedList() {
head = nullptr;
}
IntLinkedList::~IntLinkedList() {
while (head) {
IntNode* next = head->next;
delete head;
head = next;
}
cout << "end of list" << endl;
}
void IntLinkedList::Prepend(int dataValue) {
IntNode* newNode = new IntNode(dataValue);
newNode->next = head;
head = newNode;
}
int main() {
IntLinkedList* list = new IntLinkedList();
list->Prepend(2);
list->Prepend(3);
list->Prepend(6);
list->Prepend(7);
delete list;
return 0;
}