-
Notifications
You must be signed in to change notification settings - Fork 21
/
LinkedList.cpp
69 lines (46 loc) · 1.33 KB
/
LinkedList.cpp
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
//
// Created by light on 19-11-8.
//
#include "LinkedList.h"
#include "../stack/LinkedListStack.h"
#include "../queue/LinkedListQueue.h"
int main() {
LinkedList<int> *linkedList = new LinkedList<int>;
for (int i = 0; i < 10; i++) {
linkedList->add(i, i);
}
cout << linkedList->get(9) << endl;
cout << linkedList->getSize() << endl;
cout << *linkedList << endl;
linkedList->addFirst(100);
cout << *linkedList << endl;
linkedList->addLast(101);
cout << *linkedList << endl;
cout << linkedList->contains(101) << endl;
linkedList->remove(2); // index=2 delete 1
cout << *linkedList << endl;
linkedList->removeFirst();
cout << *linkedList << endl;
linkedList->removeLast();
cout << *linkedList << endl;
delete linkedList;
LinkedListStack<int> *stack = new LinkedListStack<int>();
for (int i = 0; i < 5; i++) {
stack->push(i);
cout << *stack << endl;
}
stack->pop();
cout << *stack << endl;
cout << stack->peek() << endl;
delete stack;
LinkedListQueue<int> *queue= new LinkedListQueue<int>();
for (int i = 0; i < 5; i++) {
queue->enqueue(i);
cout << *queue<< endl;
}
queue->dequeue();
cout << *queue<< endl;
cout << queue->getFront() << endl;
delete queue;
return 0;
}