-
Notifications
You must be signed in to change notification settings - Fork 0
/
stack.cpp
106 lines (98 loc) · 2.97 KB
/
stack.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include "main.hpp"
int stackAccessOperator(std::ofstream &outfile) {
outfile << std::endl << "* [STACK] Operator[] --- *" << std::endl;
STDFT::stack<int> mystack;
for (int i=0; i<5; ++i) mystack.push(i);
outfile << "Popping out elements...";
while (!mystack.empty()) {
outfile << ' ' << mystack.top();
mystack.pop();
}
outfile << std::endl;
return 0;
}
int stackAssign(std::ofstream &outfile) {
outfile << std::endl << "* [STACK] Assign --- *" << std::endl;
STDFT::stack<int> first;
STDFT::stack<int> second;
first.push(10);
first.push(20);
second = first;
first.push(30);
outfile << "Size of first: " << first.size() << std::endl;
outfile << "Size of second: " << second.size() << std::endl;
return 0;
}
int stackEmpty(std::ofstream &outfile) {
outfile << std::endl << "* [STACK] Empty --- *" << std::endl;
STDFT::stack<int> mystack;
int sum (0);
for (int i=1;i<=10;i++) mystack.push(i);
while (!mystack.empty()) {
sum += mystack.top();
mystack.pop();
}
outfile << "total: " << sum << std::endl;
return 0;
}
int stackEnd(std::ofstream &outfile) {
outfile << std::endl << "* [STACK] End --- *" << std::endl;
STDFT::stack<int> mystack;
for (int i=0; i<5; ++i) mystack.push(i);
outfile << "Popping out elements...";
while (!mystack.empty()) {
outfile << ' ' << mystack.top();
mystack.pop();
}
outfile << std::endl;
return 0;
}
int stackErase(std::ofstream &outfile) {
outfile << std::endl << "* [STACK] Erase --- *" << std::endl;
STDFT::stack<int> mystack;
for (int i=0; i<5; ++i) mystack.push(i);
mystack.pop();
outfile << "Popping out elements...";
while (!mystack.empty()) {
outfile << ' ' << mystack.top();
mystack.pop();
}
outfile << std::endl;
return 0;
}
int stackOperatorEqual(std::ofstream &outfile) {
outfile << std::endl << "* [STACK] Operator= --- *" << std::endl;
STDFT::stack<int> first;
STDFT::stack<int> second;
first.push(10);
first.push(20);
second = first;
first.push(30);
outfile << "Size of first: " << first.size() << std::endl;
outfile << "Size of second: " << second.size() << std::endl;
return 0;
}
int stackPop(std::ofstream &outfile) {
outfile << std::endl << "* [STACK] Pop --- *" << std::endl;
STDFT::stack<int> mystack;
for (int i=0; i<5; ++i) mystack.push(i);
outfile << "Popping out elements...";
while (!mystack.empty()) {
outfile << ' ' << mystack.top();
mystack.pop();
}
outfile << std::endl;
return 0;
}
int stackPush(std::ofstream &outfile) {
outfile << std::endl << "* [STACK] Push --- *" << std::endl;
STDFT::stack<int> mystack;
for (int i=0; i<5; ++i) mystack.push(i);
outfile << "Popping out elements...";
while (!mystack.empty()) {
outfile << ' ' << mystack.top();
mystack.pop();
}
outfile << std::endl;
return 0;
}