Page 141 - DCAP201_FUNDAMENTALS_OF_DATA_STRUCTURES
P. 141
Fundamentals of Data Structures
Notes 9.1 Concept of Stacks
A stack is an ordered collection of homogeneous data elements where the insertion and deletion
operations occur at one end only, called the top of the stack.
Example: Some of the examples used to visualize this data structure are:
(a) Stack of Trays (or) Plates Placed on a Table: Here, one plate is placed on top of another,
thus creating a stack of plates. Suppose, a person takes a plate off the top of the stack of
plates. The plate most recently placed on the stack is the first one to be taken off. The
bottom plate is the first one placed on the stack and the last one to be removed.
Figure 9.1: Stack of Plates
Source: http://www.tup.tsinghua.edu.cn/Resource/tsyz/034111-01.pdf
(b) Another familiar example of a stack is a Railway Station for Shunting Cars. In this example,
the last railway car placed on the stack is the first to leave.
Figure 9.2: A Railway Shunting System—Representation of a Stack
Source: http://www.tup.tsinghua.edu.cn/Resource/tsyz/034111-01.pdf
(c) Shipment in a Cargo: For the shipment of goods, they have to be loaded into a cargo.
During unloading, they are unloaded exactly in the opposite order as they are loaded, that
is, the goods which are loaded last should be unloaded first.
134 LOVELY PROFESSIONAL UNIVERSITY