... "\nPushing elements onto " << stackName <<'\n';
18 T pushValue{value};
19
20 // push element onto Stack
21 for (size_t i{0}; i < size; ++i) {
22 theStack.push(pushValue); // push element onto Stack
23 cout << pushValue << ' ';
24 pushValue += increment;
25 }
26
27 cout << "\n\nPopping elements from " << stackName <<'\n';
28
29 // pop elements from Stack
30 while (!theStack.isEmpty()) {// loop while Stack is not empty
31 cout << theStack.top() << ' ';
32 theStack.pop(); // remove top element
33 }
34
35 cout <<"\nStack is empty. Cannot pop." << endl;
36 }
37
38 int main() {
39 Stack<double> doubleStack;
40 const size_t doubleStackSize{5};
41 testStack(doubleStack, 1.1, 1.1, doubleStackSize, "doubleStack");
42
43 Stack<int> intStack;
44 const size_t ...
Get C++ How to Program, 10/e now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.