-
Notifications
You must be signed in to change notification settings - Fork 0
/
StackAndQueue.cpp
73 lines (54 loc) · 1.09 KB
/
StackAndQueue.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
70
71
72
73
#include "stdafx.h"
#include <iostream>
#include <stack>
#include <queue>
#include <string>
using namespace std;
class Test {
string name;
public:
Test(string name) : name(name) {
}
~Test() {
//cout << "Object destroyed" << endl;
}
void print() const {
cout << name << endl;
}
};
int _main10(int argc, _TCHAR* argv[]) {
//LIFO
stack<Test> testStack;
testStack.push(Test("Mike"));
testStack.push(Test("John"));
testStack.push(Test("Sue"));
cout << endl;
/*Test &test1 = testStack.top();
testStack.pop();
test1.print();
*/
while(testStack.size() > 0) {
Test &test = testStack.top();
test.print();
testStack.pop();
}
cout << endl;
//FIFO
queue<Test> testQueue;
testQueue.push(Test("Mike"));
testQueue.push(Test("John"));
testQueue.push(Test("Sue"));
cout << endl;
/*Test &test1 = testQueue.top();
testQueue.pop();
test1.print();
*/
testQueue.back().print();
cout << endl;
while(testQueue.size() > 0) {
Test &test = testQueue.front();
test.print();
testQueue.pop();
}
return 0;
}