PDS: CS 11002 Computer Sc & Engg: IIT Kharagpur 1
Data Type Stack & Queue
& %
Lect 27 Goutam Biswas
, ' $
PDS: CS 11002 Computer Sc & Engg: IIT Kharagpur 2
Stack and Queue
Both stack and queue are important data types
used in computing. They are essentially lists of
data with restricted entry and exit orderings.
& %
Lect 27 Goutam Biswas
, ' $
PDS: CS 11002 Computer Sc & Engg: IIT Kharagpur 3
Use of Stack
1. Most modern computer architecture
supports hardware stack to implement
recursive programming, exception handling,
system call implementation.
2. Compiler uses stack for syntax checking and
semantic action.
& %
Lect 27 Goutam Biswas
, ' $
PDS: CS 11002 Computer Sc & Engg: IIT Kharagpur 4
Basic Operations on a Stack
init() −→ s:Stack, empty stack.
isEmpty(s) −→ b:Boolean
top(s) −→ v:Data, if s is not empty
error, otherwise
push(s, v) −→ t:Stack
pop(s) −→ t:Stack, if s is not empty
error, otherwise
& %
Lect 27 Goutam Biswas