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

Stack data structure
Stack data structureStack data structure
Stack data structureTech_MX
 
Stack
StackStack
Notes DATA STRUCTURE - queue
Notes DATA STRUCTURE - queueNotes DATA STRUCTURE - queue
Notes DATA STRUCTURE - queue
Farhanum Aziera
 
Queue
QueueQueue
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
sumitbardhan
 
Dsa circular queue
Dsa circular queueDsa circular queue
Dsa circular queue
zzzubair
 
computer notes - Priority queue
computer notes -  Priority queuecomputer notes -  Priority queue
computer notes - Priority queue
ecomputernotes
 
Circular queues
Circular queuesCircular queues
Circular queues
Ssankett Negi
 
Queue
QueueQueue
Queue
Raj Sarode
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applications
somendra kumar
 
Priority queues
Priority queuesPriority queues
Priority queues
Yeela Mehroz
 
Queue Data Structure (w/ php egs)
Queue Data Structure (w/ php egs)Queue Data Structure (w/ php egs)
Queue Data Structure (w/ php egs)
Roman Rodomansky
 
Deque and its applications
Deque and its applicationsDeque and its applications
Deque and its applicationsJsaddam Hussain
 
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
hishamrizvi
 
Queue
QueueQueue
Ppt presentation of queues
Ppt presentation of queuesPpt presentation of queues
Ppt presentation of queues
Buxoo Abdullah
 

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

ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
AhmedHussein950959
 
Democratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek AryaDemocratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek Arya
abh.arya
 
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdfCOLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
Kamal Acharya
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
Pratik Pawar
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
Robbie Edward Sayers
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
ankuprajapati0525
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
gdsczhcet
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
MdTanvirMahtab2
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
R&R Consult
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
Divya Somashekar
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
seandesed
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.
PrashantGoswami42
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
Pipe Restoration Solutions
 
addressing modes in computer architecture
addressing modes  in computer architectureaddressing modes  in computer architecture
addressing modes in computer architecture
ShahidSultan24
 
LIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.pptLIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.ppt
ssuser9bd3ba
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
ViniHema
 

Recently uploaded (20)

ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
 
Democratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek AryaDemocratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek Arya
 
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdfCOLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
 
Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
addressing modes in computer architecture
addressing modes  in computer architectureaddressing modes  in computer architecture
addressing modes in computer architecture
 
LIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.pptLIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.ppt
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
 

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