April 2018
Intermediate to advanced
322 pages
6h 57m
English
Now, it's time to play with our new Stack data type. We are going to create our preceding diagram using the Push() operation, and then print the content of the Stack class using the Pop() operation. To ensure that the stack is not empty, we are going to use the IsEmpty() operation and we'll use the Top() operation to get the topmost element to print the value. The code should be as follows:
// Project: Stack.cbp// File : main.cpp#include <iostream>#include "Stack.h"using namespace std;int main(){ // NULL Stack<int> stackInt = Stack<int>(); // Store several numbers to the stack stackInt.Push(32); stackInt.Push(47); stackInt.Push(18); stackInt.Push(59); stackInt.Push(88); stackInt.Push(91); // list the element of stack ...