-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStacks-queues.cpp
66 lines (51 loc) · 1.13 KB
/
Stacks-queues.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
#include <iostream>
#include <stack>
#include <queue>
using namespace std;
class Test {
private:
string name;
public:
Test(string name) : name(name) {}
virtual ~Test() {
// cout << "Object destroyed \n";
}
void print() {
cout << name << endl;
}
};
int main() {
// LFIO
stack<Test> testStack;
testStack.push(Test("Mike"));
testStack.push(Test("Joe"));
testStack.push(Test("Bob"));
Test &test1 = testStack.top();
test1.print();
testStack.pop();
Test test2 = testStack.top();
test2.print();
while(testStack.size() > 0) {
Test &test = testStack.top();
test.print();
testStack.pop();
}
// FIFO
queue<Test> testQueue;
testQueue.push(Test("Mike"));
testQueue.push(Test("Joe"));
testQueue.push(Test("Bob"));
Test &test1 = testQueue.front();
test1.print();
testQueue.pop();
Test test2 = testQueue.front();
test2.print();
while(testQueue.size() > 0) {
Test &test = testQueue.front();
test.print();
testQueue.pop();
}
testQueue.back().print();
return 0;
}
// Don't forget to commit to repository (remove this comment later).