Data Structures-II Stack
& Queues
Stacks
• Stack is a linear structure in which insertion and
deletion occur in LIFO pattern
• The end of the stack in which these operations
occur is called top of stack
• Any data can inserted or deleted only through
the top
• Deletion is called pop and insertion is called
push
• Some other terminologies used with stack are:
peek, overflow, underflow
Implementation of Stacks in Python
• Peek
• <stack>[top]
• Push
• <stack>.append(<item>)
• Pop
• <stack>.pop()
Stack Implementation in Python
Applications of stack
• To reverse a String: When we
push every letter of a string till
the last character and pop them
back we get the string in
reverse
• For polish notation: Stack plays
a vital role in solving complex
arithmetic expressions in any
high-level language. For this
stack is used to convert an
expression in infix notation to
postfix and vice versa.
K
C
A
T
S
Infix topostfix
postfix Solve- 60,6,/,5,2,*,5,-,+
Infixtopostfix
Solving Postfix

7-2-data-structures-ii-stacks-queues.pptx

  • 1.
  • 2.
    Stacks • Stack isa linear structure in which insertion and deletion occur in LIFO pattern • The end of the stack in which these operations occur is called top of stack • Any data can inserted or deleted only through the top • Deletion is called pop and insertion is called push • Some other terminologies used with stack are: peek, overflow, underflow
  • 3.
    Implementation of Stacksin Python • Peek • <stack>[top] • Push • <stack>.append(<item>) • Pop • <stack>.pop()
  • 4.
  • 5.
    Applications of stack •To reverse a String: When we push every letter of a string till the last character and pop them back we get the string in reverse • For polish notation: Stack plays a vital role in solving complex arithmetic expressions in any high-level language. For this stack is used to convert an expression in infix notation to postfix and vice versa. K C A T S
  • 6.
  • 7.
  • 8.
  • 9.