-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLinkedList.cc
74 lines (63 loc) · 1.14 KB
/
LinkedList.cc
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
#include <iostream>
#include "Node.h"
#include "LinkedList.h"
using namespace std;
LinkedList::LinkedList() {
first = 0;
}
LinkedList::LinkedList(const LinkedList &l) {
if (l.first) {
first = l.first->cloneAll();
} else {
first = 0;
}
}
LinkedList::~LinkedList() {
if (first) {
first->deleteAll();
}
}
LinkedList &LinkedList::operator = (const LinkedList &l) {
if (&l != this) {
if (first) {
first->deleteAll();
}
if (l.first) {
first = l.first->cloneAll();
} else {
first = 0;
}
}
return *this;
}
void LinkedList::add(int v) {
first = new Node(first, v);
}
bool LinkedList::operator == (const LinkedList &l) const {
if (first) {
return first->equalAll(l.first);
} else {
return l.first == 0;
}
}
bool LinkedList::contains(int v) const {
return first && first->contains(v);
}
int LinkedList::size() const {
if (first) {
return first->size();
} else {
return 0;
}
}
void LinkedList::print() const {
Node *n;
for (n = first; n != 0; n = n->next) {
cout << n->value;
if (n->next) {
cout << ", ";
} else {
cout << "\n";
}
}
}