SlideShare a Scribd company logo
1 of 18
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

More Related Content

Viewers also liked (20)

Stack data structure
Stack data structureStack data structure
Stack data structure
 
Stack
StackStack
Stack
 
Notes DATA STRUCTURE - queue
Notes DATA STRUCTURE - queueNotes DATA STRUCTURE - queue
Notes DATA STRUCTURE - queue
 
Queue
QueueQueue
Queue
 
358 33 powerpoint-slides_9-stacks-queues_chapter-9
358 33 powerpoint-slides_9-stacks-queues_chapter-9358 33 powerpoint-slides_9-stacks-queues_chapter-9
358 33 powerpoint-slides_9-stacks-queues_chapter-9
 
Dsa circular queue
Dsa circular queueDsa circular queue
Dsa circular queue
 
computer notes - Priority queue
computer notes -  Priority queuecomputer notes -  Priority queue
computer notes - Priority queue
 
Queue
QueueQueue
Queue
 
Circular queues
Circular queuesCircular queues
Circular queues
 
Heaps & priority queues
Heaps & priority queuesHeaps & priority queues
Heaps & priority queues
 
Stack a Data Structure
Stack a Data StructureStack a Data Structure
Stack a Data Structure
 
Queue
QueueQueue
Queue
 
Priority queue
Priority queuePriority queue
Priority queue
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applications
 
Priority queues
Priority queuesPriority queues
Priority queues
 
Queue Data Structure (w/ php egs)
Queue Data Structure (w/ php egs)Queue Data Structure (w/ php egs)
Queue Data Structure (w/ php egs)
 
Deque and its applications
Deque and its applicationsDeque and its applications
Deque and its applications
 
C++ Notes by Hisham Ahmed Rizvi for Class 12th Board Exams
C++ Notes by Hisham Ahmed Rizvi for Class 12th Board ExamsC++ Notes by Hisham Ahmed Rizvi for Class 12th Board Exams
C++ Notes by Hisham Ahmed Rizvi for Class 12th Board Exams
 
Queue
QueueQueue
Queue
 
Ppt presentation of queues
Ppt presentation of queuesPpt presentation of queues
Ppt presentation of queues
 

Recently uploaded

THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTIONTHE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTIONjhunlian
 
welding defects observed during the welding
welding defects observed during the weldingwelding defects observed during the welding
welding defects observed during the weldingMuhammadUzairLiaqat
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substationstephanwindworld
 
Main Memory Management in Operating System
Main Memory Management in Operating SystemMain Memory Management in Operating System
Main Memory Management in Operating SystemRashmi Bhat
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvLewisJB
 
Internet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptxInternet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptxVelmuruganTECE
 
11. Properties of Liquid Fuels in Energy Engineering.pdf
11. Properties of Liquid Fuels in Energy Engineering.pdf11. Properties of Liquid Fuels in Energy Engineering.pdf
11. Properties of Liquid Fuels in Energy Engineering.pdfHafizMudaserAhmad
 
Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...
Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...
Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...Erbil Polytechnic University
 
Autonomous emergency braking system (aeb) ppt.ppt
Autonomous emergency braking system (aeb) ppt.pptAutonomous emergency braking system (aeb) ppt.ppt
Autonomous emergency braking system (aeb) ppt.pptbibisarnayak0
 
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgUnit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgsaravananr517913
 
home automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasadhome automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasadaditya806802
 
Mine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptxMine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptxRomil Mishra
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptSAURABHKUMAR892774
 
Class 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm SystemClass 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm Systemirfanmechengr
 

Recently uploaded (20)

THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTIONTHE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
welding defects observed during the welding
welding defects observed during the weldingwelding defects observed during the welding
welding defects observed during the welding
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substation
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
Main Memory Management in Operating System
Main Memory Management in Operating SystemMain Memory Management in Operating System
Main Memory Management in Operating System
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvv
 
Internet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptxInternet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptx
 
11. Properties of Liquid Fuels in Energy Engineering.pdf
11. Properties of Liquid Fuels in Energy Engineering.pdf11. Properties of Liquid Fuels in Energy Engineering.pdf
11. Properties of Liquid Fuels in Energy Engineering.pdf
 
Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...
Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...
Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
Autonomous emergency braking system (aeb) ppt.ppt
Autonomous emergency braking system (aeb) ppt.pptAutonomous emergency braking system (aeb) ppt.ppt
Autonomous emergency braking system (aeb) ppt.ppt
 
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgUnit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
 
home automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasadhome automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasad
 
Mine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptxMine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptx
 
Designing pile caps according to ACI 318-19.pptx
Designing pile caps according to ACI 318-19.pptxDesigning pile caps according to ACI 318-19.pptx
Designing pile caps according to ACI 318-19.pptx
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.ppt
 
Class 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm SystemClass 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm System
 

Stack & queues

  • 2. 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
  • 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 We define a stack as an ADT as shown below:
  • 8. Example 1 Figure 1 shows a segment of an algorithm tthhaatt aapppplliieess tthhee pprreevviioouussllyy ddeeffiinneedd ooppeerraattiioonnss oonn aa ssttaacckk SS.. Figure 1:- Example 1
  • 10. 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
  • 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 We define a queue as an ADT as shown below:
  • 16. Example 2 Figure 2 shows a segment of an algorithm tthhaatt aapppplliieess tthhee pprreevviioouussllyy ddeeffiinneedd ooppeerraattiioonnss oonn aa qquueeuuee QQ.. Figure 2:- Example 2