KEMBAR78
Stack & queues | PPT
STACKS & QUEUES
STACKS 
AA ssttaacckk iiss aa rreessttrriicctteedd lliinneeaarr lliisstt iinn wwhhiicchh aallll aaddddiittiioonnss 
aanndd ddeelleettiioonnss aarree mmaaddee aatt oonnee eenndd,, tthhee ttoopp.. IIff wwee iinnsseerrtt aa 
sseerriieess ooff ddaattaa iitteemmss iinnttoo aa ssttaacckk aanndd tthheenn rreemmoovvee tthheemm,, 
tthhee oorrddeerr ooff tthhee ddaattaa iiss rreevveerrsseedd.. TThhiiss rreevveerrssiinngg aattttrriibbuuttee 
iiss wwhhyy ssttaacckkss aarree kknnoowwnn aass llaasstt iinn,, ffiirrsstt oouutt ((LLIIFFOO)) ddaattaa 
ssttrruuccttuurreess.. 
Figure:-Three representations of stacks
Operations on stacks 
There are four basic operations, stack, push, pop and empty, 
that we define in this chapter. 
The stack operation 
The stack operation creates an empty stack. The following 
shows the format. 
Figure:- Stack operation
The push operation 
The push operation inserts an item at the top of the stack. 
The following shows the format. 
Figure:- Push operation
The pop operation 
The pop operation deletes the item at the top of the stack. 
The following shows the format. 
Figure:- Pop operation
The empty operation 
The empty operation checks the status of the stack. The 
following shows the format. 
This operation returns true if the stack is empty and false if 
the stack is not empty.
Stack ADT 
We define a stack as an ADT as shown below:
Example 1 
Figure 1 shows a segment of an algorithm tthhaatt aapppplliieess tthhee 
pprreevviioouussllyy ddeeffiinneedd ooppeerraattiioonnss oonn aa ssttaacckk SS.. 
Figure 1:- Example 1
Figure:- Stack implementations
QUEUES 
AA qquueeuuee iiss aa lliinneeaarr lliisstt iinn wwhhiicchh ddaattaa ccaann oonnllyy bbee 
iinnsseerrtteedd aatt oonnee eenndd,, ccaalllleedd tthhee rreeaarr,, aanndd ddeelleetteedd ffrroomm tthhee 
ootthheerr eenndd,, ccaalllleedd tthhee ffrroonntt.. TThheessee rreessttrriiccttiioonnss eennssuurree tthhaatt 
tthhee ddaattaa iiss pprroocceesssseedd tthhrroouugghh tthhee qquueeuuee iinn tthhee oorrddeerr iinn 
wwhhiicchh iitt iiss rreecceeiivveedd.. IInn ootthheerr wwoorrddss,, aa qquueeuuee iiss aa ffiirrsstt 
iinn,, ffiirrsstt oouutt ((FFIIFFOO)) ssttrruuccttuurree.. 
Figure:- Two representation of queues
Operations on queues 
Although we can define many operations for a queue, four 
are basic: queue, enqueue, dequeue and empty, as defined 
below. 
The queue operation 
The queue operation creates an empty queue. The following 
shows the format. 
Figure:- The queue operation
The enqueue operation 
The enqueue operation inserts an item at the rear of the 
queue. The following shows the format. 
Figure:- The enqueue operation
The dequeue operation 
The dequeue operation deletes the item at the front of the 
queue. The following shows the format. 
Figure:- The dequeue operation
The empty operation 
The empty operation checks the status of the queue. The 
following shows the format. 
This operation returns true if the queue is empty and false if 
the queue is not empty.
Queue ADT 
We define a queue as an ADT as shown below:
Example 2 
Figure 2 shows a segment of an algorithm tthhaatt aapppplliieess tthhee 
pprreevviioouussllyy ddeeffiinneedd ooppeerraattiioonnss oonn aa qquueeuuee QQ.. 
Figure 2:- Example 2
Figure:- Queue implementations
THANK YOU

Stack & queues

  • 1.
  • 2.
    STACKS AA ssttaacckkiiss aa rreessttrriicctteedd lliinneeaarr lliisstt iinn wwhhiicchh aallll aaddddiittiioonnss aanndd ddeelleettiioonnss aarree mmaaddee aatt oonnee eenndd,, tthhee ttoopp.. IIff wwee iinnsseerrtt aa sseerriieess ooff ddaattaa iitteemmss iinnttoo aa ssttaacckk aanndd tthheenn rreemmoovvee tthheemm,, tthhee oorrddeerr ooff tthhee ddaattaa iiss rreevveerrsseedd.. TThhiiss rreevveerrssiinngg aattttrriibbuuttee iiss wwhhyy ssttaacckkss aarree kknnoowwnn aass llaasstt iinn,, ffiirrsstt oouutt ((LLIIFFOO)) ddaattaa ssttrruuccttuurreess.. Figure:-Three representations of stacks
  • 3.
    Operations on stacks There are four basic operations, stack, push, pop and empty, that we define in this chapter. The stack operation The stack operation creates an empty stack. The following shows the format. Figure:- Stack operation
  • 4.
    The push operation The push operation inserts an item at the top of the stack. The following shows the format. Figure:- Push operation
  • 5.
    The pop operation The pop operation deletes the item at the top of the stack. The following shows the format. Figure:- Pop operation
  • 6.
    The empty operation The empty operation checks the status of the stack. The following shows the format. This operation returns true if the stack is empty and false if the stack is not empty.
  • 7.
    Stack ADT Wedefine a stack as an ADT as shown below:
  • 8.
    Example 1 Figure1 shows a segment of an algorithm tthhaatt aapppplliieess tthhee pprreevviioouussllyy ddeeffiinneedd ooppeerraattiioonnss oonn aa ssttaacckk SS.. Figure 1:- Example 1
  • 9.
  • 10.
    QUEUES AA qquueeuueeiiss aa lliinneeaarr lliisstt iinn wwhhiicchh ddaattaa ccaann oonnllyy bbee iinnsseerrtteedd aatt oonnee eenndd,, ccaalllleedd tthhee rreeaarr,, aanndd ddeelleetteedd ffrroomm tthhee ootthheerr eenndd,, ccaalllleedd tthhee ffrroonntt.. TThheessee rreessttrriiccttiioonnss eennssuurree tthhaatt tthhee ddaattaa iiss pprroocceesssseedd tthhrroouugghh tthhee qquueeuuee iinn tthhee oorrddeerr iinn wwhhiicchh iitt iiss rreecceeiivveedd.. IInn ootthheerr wwoorrddss,, aa qquueeuuee iiss aa ffiirrsstt iinn,, ffiirrsstt oouutt ((FFIIFFOO)) ssttrruuccttuurree.. Figure:- Two representation of queues
  • 11.
    Operations on queues Although we can define many operations for a queue, four are basic: queue, enqueue, dequeue and empty, as defined below. The queue operation The queue operation creates an empty queue. The following shows the format. Figure:- The queue operation
  • 12.
    The enqueue operation The enqueue operation inserts an item at the rear of the queue. The following shows the format. Figure:- The enqueue operation
  • 13.
    The dequeue operation The dequeue operation deletes the item at the front of the queue. The following shows the format. Figure:- The dequeue operation
  • 14.
    The empty operation The empty operation checks the status of the queue. The following shows the format. This operation returns true if the queue is empty and false if the queue is not empty.
  • 15.
    Queue ADT Wedefine a queue as an ADT as shown below:
  • 16.
    Example 2 Figure2 shows a segment of an algorithm tthhaatt aapppplliieess tthhee pprreevviioouussllyy ddeeffiinneedd ooppeerraattiioonnss oonn aa qquueeuuee QQ.. Figure 2:- Example 2
  • 17.
  • 18.