Building a Stack ADT

A stack data type is a list with some restriction in the list's operations. It can only perform the operations from one side, called the top. There are three basic operations in the Stack data type, and they are Top(), Push(), and Pop(). The Top() operation is used to fetch the value of the top position item only, the Push() operation will insert the new item in the top position, and the Pop() operation will remove the item in the top position. The stack is also known as a Last In First Out (LIFO) data type. To support these three operations, we will add one operation to the stack, which is IsEmpty(), to indicate whether the stack has elements or not. Please take a look at the following stack diagram:

As we can see in ...

Get C++ Data Structures and Algorithms 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.