Dsa L7
Dsa L7
DR . MOHAMMED AL-HUBAISHI
2
Introduction to Stack Data Structure
This means that the last element added to the stack is the
first element to be removed.
4
Operations on STACK
► Push
► Pop
1. Any object (either book or a coin) can be accessed only from the top.
2. Any object can be added only at the top.
Dr. Mohammed Al-Hubaishi
5
Operations on STACK
https://onlinegdb.com/E4Xb9HyXv
12
Implementation using Linked Lists
https://onlinegdb.com/fs7VogR9a
13
Real-world Applications of Stack
https://onlinegdb.com/HcqwyOg1p
16
Reversing Strings using Stack
String input :
REVERSE
A simple application of stack is reversing strings.
► To reverse a string, the characters of string are pushed
onto the stack one by one as the string is read from left to
right.
E TOP
► Once all the characters of string are pushed onto stack, S
they are popped one by one. Since the character last
R
pushed in comes out first, subsequent pop operation
results in the reversal of the string. E
https://onlinegdb.com/z-xhqIJTz V
R
Dr. Mohammed Al-Hubaishi
Stack
17
sort a stack using recursion
https://onlinegdb.com/ICdXXgNno
18
Stack class
output