Your SlideShare is downloading. ×
Lecturestacks 110802115132-phpapp02-120309093554-phpapp02
Upcoming SlideShare
Loading in...5

Thanks for flagging this SlideShare!

Oops! An error has occurred.

Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Lecturestacks 110802115132-phpapp02-120309093554-phpapp02


Published on

Published in: Education, Technology

  • Be the first to comment

  • Be the first to like this

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

No notes for slide


  • 1. S T A K
  • 2. INTRODUCTION● Array allows to insert and delete an element at any place in the list● STACK is a list of elements● It is a linear data structure● Insertion and deletion operation is performed only at one end – known as top of stack● Also known as Last-in-First-out (LIFO), entries are removed in reverse order of insertion
  • 3. BASIC OPERATIONS OF STACKS● push -- insert item on stack● pop -- remove item from stack● peek -- examine, but don’t remove item● isEmpty – reports whether or not stack is empty● isFull- reports whether or not stack is full● size – returns # of items in stack
  • 4. PUSH OPERATION ● Inserting element in a stack is known as PUSH ● When elements are inserted continuously to the stack it grows at one end i.e. top Top 9 => Top 6 8 => Top -7 -7 -7 => Top 8 8 8 8 => Top 5 5 5 5 5 =>Top =NULL
  • 5. POP OPERATION ● Removing of element from a stack is known as pop ● When elements are removed continuously from a stack, it shrinks at the same end i.e. topTop 9=> 8 Top 6 => -7 -7 Top -7 => 8 8 8 Top 8 => 5 5 5 5 Top 5 => Top = NULL
  • 6. STACKS CONDITIONS● Depending on implementation, ● Important to know if stack is may be necessary to check if empty -- attempt to remove an stack is full -- attempt to add item from an empty stack is an item to a full stack is an overflow underflow error. error Top 9 => 8 -7 8 5 Top = NULL
  • 7. PUSH(STACK, TOP, MAXSTK, ITEM)STACK - Linear Array, TOP – location of top element in stack,MAXSTK – Numbers of elements that be stored in Stack,ITEM – value that has to be inserted in stack STEP 1. if top = MaxStk, then print “Overflow” and return STEP 2. set top=top + 1 STEP 3. set STACK[top] = item STEP 4. Return
  • 8. PUSH(STACK, TOP)STACK - Linear Array, TOP – location of top element in stack,ITEM – value that has to be inserted in stack 1. [check for underflow of the stack] if TOP=-1 then Write(“stack underflow on pop) end if 2. [ Assign the top element of the stack to ITEM] ITEM = STACK[TOP] 2. [decrement pointer] TOP=TOP-1 3. [return former top element of the stack] Return(ITEM) 4. Exit
  • 9. PEEP(STACK,TOP)1. [check for stack underflow]if TOP-I+1<=0 thenWrite (“stack underflow on peep”)end if2. [Return the top element of the stack]Return(stack[TOP-MAX+1])3. Exit
  • 10. APPLICATIONS OF STACK● Undo● Redo● Function Call● Recursive Function Call● Convert infix to Postfix expression● Convert infix to Prefix expression● Evaluate infix expression● Tower of hanoi● Reverse string or list or file