S                      T                      A                      Cwww.eshikshak.co.in   K
INTRODUCTION● Array allows to insert and delete an element at any place in the list● STACK is a list of elements● It is a ...
BASIC OPERATIONS OF STACKS● push -- insert item on stack● pop -- remove item from stack● peek -- examine, but don’t remove...
PUSH OPERATION   ● Inserting element in a stack is known as PUSH   ● When elements are inserted continuously to the stack ...
POP OPERATION  ● Removing of element from a stack is known as pop  ● When elements are removed continuously from a stack, ...
STACKS CONDITIONS● Depending on implementation,                                        ● Important to know if stack is  ma...
PUSH(STACK, TOP, MAXSTK, ITEM)STACK - Linear Array, TOP – location of top element in stack,MAXSTK – Numbers of elements th...
PUSH(STACK, TOP)STACK - Linear Array, TOP – location of top element in stack,ITEM – value that has to be inserted in stack...
PEEP(STACK,TOP)1. [check for stack underflow]if TOP-I+1<=0 thenWrite (“stack underflow on peep”)end if2. [Return the top e...
APPLICATIONS OF STACK● Undo● Redo● Function Call● Recursive Function Call● Convert infix to Postfix expression● Convert in...
Upcoming SlideShare
Loading in...5
×

Lecturestacks 110802115132-phpapp02-120309093554-phpapp02

405

Published on

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
405
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
14
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Lecturestacks 110802115132-phpapp02-120309093554-phpapp02

  1. 1. S T A Cwww.eshikshak.co.in K
  2. 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 www.eshikshak.co.in
  3. 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 www.eshikshak.co.in
  4. 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 www.eshikshak.co.in
  5. 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 www.eshikshak.co.in
  6. 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 www.eshikshak.co.in
  7. 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 www.eshikshak.co.in
  8. 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 www.eshikshak.co.in
  9. 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 www.eshikshak.co.in
  10. 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 www.eshikshak.co.in
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×