-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfig_18_2_Stack.cpp
More file actions
45 lines (34 loc) · 973 Bytes
/
fig_18_2_Stack.cpp
File metadata and controls
45 lines (34 loc) · 973 Bytes
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
#include <iostream>
#include "fig_18_2_Stack.h"
using namespace std;
int main() {
Stack<double> doubleStack;
const size_t doubleStackSize{ 5 };
double doubleValue{ 1.1 };
cout << "Pushing elements onto doubleStack\n";
for (size_t i{ 0 }; i < doubleStackSize; ++i) {
doubleStack.push(doubleValue);
cout << doubleValue << ' ';
doubleValue += 1.1;
}
cout << "\n\nPopping elements from doubleStack\n";
while (!doubleStack.isEmpty()) {
cout << doubleStack.top() << ' ';
doubleStack.pop();
}
cout << "\nStack is empty, cannot pop.\n";
Stack<int> intStack;
const size_t intStackSize{ 10 };
int intValue{ 1 };
cout << "\nPushing elements onto intStack\n";
for (size_t i{ 0 }; i < intStackSize; ++i) {
intStack.push(intValue);
cout << intValue++ << ' ';
}
cout << "\n\nPopping elemnts from intStack\n";
while (!intStack.isEmpty()) {
cout << intStack.top() << ' ';
intStack.pop();
}
cout << "\nStack is empty, cannot pop. " << endl;
}