Chapter 6
Stacks
Stack data structure is exclusively discussed in this chapter. Representation and implementation of stacks are explained along with examples. Four of the common applications are stated and illustrated in detail.
6.1 INTRODUCTION
A stack is a linear data structure in which insertion and deletion of elements are done at only one end, which is termed as Top of stack. The last element that is inserted will be the first element to be deleted. Therefore, this is referred to as a Last In First Out (LIFO) structure.
Examples
- The stack of trays in a cafeteria
- A stack of plates in a cupboard
Let ST be a stack with elements 10, 20, 30. The element 30 is pointed by the top. When the new element 40 is to be added, it is inserted at the ...
Get Data Structures and Algorithms Using C++ 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.