Wednesday 8 March 2017

Algorithm for PUSH and POP operation in a STACK




Step 1 :   Start
Step 2 :   Initialize TOP = 1
Step 3 :   PUSH  n elements to STACK
Step 4 :   Print
               1. PUSH
               2.POP
Step 5 :  Read choice , if choice = 1 go to step-6
              if choice = 2 go to step-8
              else go to step-11
Step 6 :  If  TOP >=  ( MAX_SIZE - 1)
                 print "stack full"
              Else go to step-7
Step 7 :  7.1   Read Item
              7.2   TOP = TOP + 1
              7.3   stack [TOP] = Item
              go to step-10
Step 8 :  if   top < 0
                   print "stack is empty"
              else go to step-9
Step 9 :  9.1 Item = stack [TOP]
              9.2 TOP = TOP - 1
Step 10 : Print elements of stack
Step 11 : Stop


No comments:

Post a Comment

How to Invert an SVG image using CSS ?

You can invert your svg easily by using following css code svg { -webkit-filter: invert(100%); /* safari 6.0 - 9.0 */ filter...