KEMBAR78
Stack operation algorithms with example | PPTX
Stack operation algorithms
with example
KIKANI NAMAN BHARATBHAI
20SS02IT027
DATA STRUCTURES
What is Stack?
• A stack is called a last-in-first-out (LIFO) collection. This
means that the last thing we added (pushed) is the first thing
that gets pulled (popped) off.
• A stack is a sequence of items that are accessible at only one
end of the sequence.
Operations that can be performed on STACK:
 PUSH.
 POP.
Procedure/Methodology
PUSH : It is used to insert items into the stack.
POP: It is used to delete items from stack.
TOP: It represents the current location of data in stack.
ALGORITHM OF INSERTION IN STACK: (PUSH)
1. Insertion(a,top,item,max)
2. If top=max then
3. print ‘STACK OVERFLOW’
4. exit else
5. top=top+1 end if
6. a[top]=item
7. Exit
ALGORITHM OF DELETION IN STACK: (POP)
1. Deletion(a,top,item)
2. If top=0 then
3. print ‘STACK UNDERFLOW’
4. exit else
5. item=a[top] end if
6. top=top-1
7. Exit
ALGORITHM OF DISPLAY IN STACK:
• 1. Display(top,i,a[i]) 2.If top=0 then
• 2. Print ‘STACK EMPTY’
• Exit Else
• 3. For i=top to 0
• Print a[i] End for
• 4. exit
Conversion of INFIX to POSTFIX conversion:
• Example: 2+(4-1)*3 step1
• 2+41-*3 step2
• 2+41-3* step3
• 241-3*+ step4
Example:
THANK YOU

Stack operation algorithms with example

  • 1.
    Stack operation algorithms withexample KIKANI NAMAN BHARATBHAI 20SS02IT027 DATA STRUCTURES
  • 2.
    What is Stack? •A stack is called a last-in-first-out (LIFO) collection. This means that the last thing we added (pushed) is the first thing that gets pulled (popped) off. • A stack is a sequence of items that are accessible at only one end of the sequence.
  • 3.
    Operations that canbe performed on STACK:  PUSH.  POP.
  • 4.
    Procedure/Methodology PUSH : Itis used to insert items into the stack. POP: It is used to delete items from stack. TOP: It represents the current location of data in stack.
  • 5.
    ALGORITHM OF INSERTIONIN STACK: (PUSH) 1. Insertion(a,top,item,max) 2. If top=max then 3. print ‘STACK OVERFLOW’ 4. exit else 5. top=top+1 end if 6. a[top]=item 7. Exit
  • 6.
    ALGORITHM OF DELETIONIN STACK: (POP) 1. Deletion(a,top,item) 2. If top=0 then 3. print ‘STACK UNDERFLOW’ 4. exit else 5. item=a[top] end if 6. top=top-1 7. Exit
  • 7.
    ALGORITHM OF DISPLAYIN STACK: • 1. Display(top,i,a[i]) 2.If top=0 then • 2. Print ‘STACK EMPTY’ • Exit Else • 3. For i=top to 0 • Print a[i] End for • 4. exit
  • 8.
    Conversion of INFIXto POSTFIX conversion: • Example: 2+(4-1)*3 step1 • 2+41-*3 step2 • 2+41-3* step3 • 241-3*+ step4
  • 9.
  • 10.

Editor's Notes