Skip to Content
C++ Data Structures and Algorithms
book

C++ Data Structures and Algorithms

by Wisnu Anggoro
April 2018
Intermediate to advanced content levelIntermediate to advanced
322 pages
6h 57m
English
Packt Publishing
Content preview from C++ Data Structures and Algorithms

Consuming a Stack ADT

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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Data Structures and Algorithms Using C++

Data Structures and Algorithms Using C++

Ananda Rao Akepogu, Radhika Raju Palagiri
C++ Data Structures and Algorithm Design Principles

C++ Data Structures and Algorithm Design Principles

John Carey, Anil Achary, Shreyans Doshi, Payas Rajan
C++ Plus Data Structures, 6th Edition

C++ Plus Data Structures, 6th Edition

Nell Dale, Chip Weems, Tim Richards

Publisher Resources

ISBN: 9781788835213Supplemental Content