You are on page 1of 3

# :'% Chapter 10 LINKED LISTS, STACKS AND QUEUES The above program calls function Push() for pushing element

into stack-array. This function firstly tests for STACK- !"" con#ition an# if it is full\$ it returns - %\$ other&ise\$ it successfully inserts element into stack an# returns '. %'.(.) * +eletion in a Stack (as an Array) , Popping Popping i.e., #eletion of an element from a stack removes the element at top most position. or instance\$ from the stack sho&n in ig. %'./(c)\$ the top most element\$ &hich is L, can be poppe# an# after popping L, the stack looks as sho&n in ig. %'.-(A). After popping another element P\$ the stack looks as ig. %'.-(f)). )n case the last element is poppe#\$ the stack becomes empty. )f one tries to #elete an element from an empty stack\$ this is calle# un#erflo&.

POP Once

.

N
(a) (b) ig. %'.- Popping operation in a stack (#eletion).

ALCORITH M 01 irstly\$ check for un#erflo& con#ition 10 Poppin2 from %. )f top 33 -% then Array-Stack 4 2. Print5 !n#erflo&66 5 3. 78it from program 9 4. 7lse < 5. print stack(top) 6. top 3 top - % 01 top move#\$ so that the top most element becomes 10 01 inaccessible &hich is a sort of a #eletion 10 } 7. 7.+. The C++ implementation of above algorithm is given in the following program :

/ Popping from Array-Stack .:'% 10 Chapter P rogram %'.

B )f overflo& occurs\$ it returns -% an# if it successfully pushes the element\$ it returns '.:'% Chapter 10 .lnclu#e<iostream. ) B unction Pop() receives the Stack-array\$ an# its topCs position. )f un#erflo& occurs\$ B it returns -% an# if it successfully pops the element\$ it returns poppe# element.inclu#e<process.h= . .h= 00 for e8it() int Pop(int > ?\$ int@)A 00 prototype int Push(int > ?\$ int@\$ int)A 00 prototype voi# +isplay(int > ?\$ int)A 00 prototype I*-----------------------------------------------------------B unction Push() receives the Stack-array\$ its top position an# element to be pushe# into. ) B unction +isplay() #isplays the stack after insertion.