SlideShare a Scribd company logo
1 of 13
Name:-Sunipa Bera
B. Tech CSE (CSF)
Roll No. :-17
Subject: DS
Prn No.: 190105181016
Topic:- Stack & Queue
Stack
&
Queue
What is a
Stack?
A stack is a data structure of ordered items suc
h that items can be inserted and removed only
at one end.
• A stack is a LIFO (Last-In/ First-Out) data
structure
• A stack is sometimes also called a pushdown
store.
• What are some applications of stacks?
 Program execution
 Parsing
 Evaluating postfix expressions
PUSH
Place an item on the Stack
PEEK
Look at the item on top of the stack, but do not
remove it.
POP
Look at the item on the stack and remove it.
What
can we
do with
Stack?
Stacks
Using a IStack
 A balance of braces.
- (()) balanced braces
- ()(()()))) not balanced braces
 How can you use Istack to check a br
ace is balanced or not?
Interface IStack Answer:
Problem
When you implement the above requirement, you ignore the implementation details of Istack.
What happens if we try to pop an item off the stack
when the stack is empty?
This is called a stack underflow. The
pop method needs some way of telling
us that this has happened. In java we
use the
java.util.EmptyStackException
Interface Istack
{
boolean empty();
void push(char c);
char pop();
char peek();
}
Implementing a
stack using an
array is fairly easy.
• The bottom of the stack is at
data[0]
• The top of the stack is at
data[numItems-1]
• push onto the stack at
data[numItems]
• pop off of the stack at
data[numItems-1]
Implementing a
stack using a
linked list isn’t
that bad either…
• Store the items in the stack in a linked
list
• The top of the stack is the head node,
the bottom of the stack is the end of
the list
• push by adding to the front of the list
• pop by removing from the front of the
list
Reversing A Word
We can use a stack to reverse the letters in a word. How?
Read each letter in th
e word and push it o
nto the
stack
When you reach
the end of the
word, pop the
letters off the stack an
d print them out.
What is a
Queue?
A data structure of ordered items such that item
s can be inserted only at one end and removed a
t the other end.
e.g. A line at the supermarket
• A queue is called a FIFO (First in-First out)
data structure.
• What are some applications of queues?
 Round-robin scheduling in processors
 Input/ Output processing
 Queueing of packets for delivery in
networks
What we can do with Queue?
These ops are called insert ant getfront in order to simplify things.
Add an item to the queue.
Enqueue
Remove an item from the
queue
Dequeue
Implementation of
Queue
• Just like a stack, we can implementing a queue in two ways: 1) Using an array
2). Using a linked list.
Problems: Using an array to implement a queue is significantly harder than using
an array to implement a stack. Why?
Solution: Unlike a stack, where we add and remove at the same end, in a queue we
add to one end and remove from the other.
Implementing a queue using a
linked list is still easy:
• Front of the queue is stored as the head node
of the linked list, rear of the queue is stored
as the tail node.
• Enqueue by adding to the end of the list
• Dequeue by removing from the front of the
list.
Infographic Style
Insert the title of your subtitle Here
Option 1
Option 2
Option 2 Sketch of Insert
Option 2 sketch of
getforce
 Enqueue at data[0] and shift all of
the rest of the items in the array
down to make room.
 Dequeue from data[numItems-1]
• Enqueue at data[rear+1]
• Dequeue at data[front]
• The rear variable always contains the
index of the last item in the queue.
• The front variable always contains the
index of the first item in the queue.
• When we reach the end of the array,
wrap around to the front again.
insert(Object item)
{
if(manyItems == 0) front = rear = 0;
else rear = (rear + 1) mod size;
data[rear] = item;
manyItems++;
}
Object getFront()
{
answer = data[front];
front = (front + 1) mod size;
manyItems--;
return answer
Biblography
- W3school
- tutorialspoint
Thank You

More Related Content

What's hot

Stacks and queues
Stacks and queuesStacks and queues
Stacks and queuesAbbott
 
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queuesFallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queuesSnehilKeshari
 
Ppt presentation of queues
Ppt presentation of queuesPpt presentation of queues
Ppt presentation of queuesBuxoo Abdullah
 
Stack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi LecturerStack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi Lecturergomathi chlm
 
Stack Data Structure
Stack Data StructureStack Data Structure
Stack Data StructureRabin BK
 
Queue data structure
Queue data structureQueue data structure
Queue data structureanooppjoseph
 
Queues in data structures
Queues in data structuresQueues in data structures
Queues in data structuresEdison Tusifu
 
Queues-and-CQueue-Implementation
Queues-and-CQueue-ImplementationQueues-and-CQueue-Implementation
Queues-and-CQueue-Implementationshaik faroq
 
Review of basic data structures
Review of basic data structuresReview of basic data structures
Review of basic data structuresDeepa Rani
 
Fp growth algorithm
Fp growth algorithmFp growth algorithm
Fp growth algorithmPradip Kumar
 
Stack data structure in Data Structure using C
Stack data structure in Data Structure using C Stack data structure in Data Structure using C
Stack data structure in Data Structure using C Meghaj Mallick
 
Presentation on Elementary data structures
Presentation on Elementary data structuresPresentation on Elementary data structures
Presentation on Elementary data structuresKuber Chandra
 

What's hot (20)

Queue in Data Structure
Queue in Data StructureQueue in Data Structure
Queue in Data Structure
 
Stacks and queues
Stacks and queuesStacks and queues
Stacks and queues
 
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queuesFallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
 
Queues
QueuesQueues
Queues
 
Data Structures
Data StructuresData Structures
Data Structures
 
Ppt presentation of queues
Ppt presentation of queuesPpt presentation of queues
Ppt presentation of queues
 
Stack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi LecturerStack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi Lecturer
 
Stack Data Structure
Stack Data StructureStack Data Structure
Stack Data Structure
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
 
Queues in data structures
Queues in data structuresQueues in data structures
Queues in data structures
 
Queues-and-CQueue-Implementation
Queues-and-CQueue-ImplementationQueues-and-CQueue-Implementation
Queues-and-CQueue-Implementation
 
Review of basic data structures
Review of basic data structuresReview of basic data structures
Review of basic data structures
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Stack and queue
Stack and queueStack and queue
Stack and queue
 
Fp growth algorithm
Fp growth algorithmFp growth algorithm
Fp growth algorithm
 
Data structure stack&queue basics
Data structure stack&queue   basicsData structure stack&queue   basics
Data structure stack&queue basics
 
Stack data structure in Data Structure using C
Stack data structure in Data Structure using C Stack data structure in Data Structure using C
Stack data structure in Data Structure using C
 
Data Analysis packages
Data Analysis packagesData Analysis packages
Data Analysis packages
 
Presentation on Elementary data structures
Presentation on Elementary data structuresPresentation on Elementary data structures
Presentation on Elementary data structures
 
stack & queue
stack & queuestack & queue
stack & queue
 

Similar to Ds stack & queue (20)

Lecture9_StackQueue.ppt
Lecture9_StackQueue.pptLecture9_StackQueue.ppt
Lecture9_StackQueue.ppt
 
StackQueue.ppt
StackQueue.pptStackQueue.ppt
StackQueue.ppt
 
Stack in Sata Structure
Stack in Sata StructureStack in Sata Structure
Stack in Sata Structure
 
STACK.pptx
STACK.pptxSTACK.pptx
STACK.pptx
 
Difference between stack and queue
Difference between stack and queueDifference between stack and queue
Difference between stack and queue
 
stack.pptx
stack.pptxstack.pptx
stack.pptx
 
2.1 STACK & QUEUE ADTS
2.1 STACK & QUEUE ADTS2.1 STACK & QUEUE ADTS
2.1 STACK & QUEUE ADTS
 
Queues
Queues Queues
Queues
 
unit 5 stack & queue.ppt
unit 5 stack & queue.pptunit 5 stack & queue.ppt
unit 5 stack & queue.ppt
 
Data structures
Data structuresData structures
Data structures
 
queue.pptx
queue.pptxqueue.pptx
queue.pptx
 
ppt.pptx
ppt.pptxppt.pptx
ppt.pptx
 
Stack and Queue.pptx
Stack and Queue.pptxStack and Queue.pptx
Stack and Queue.pptx
 
Stack & Queue
Stack & QueueStack & Queue
Stack & Queue
 
5.-Stacks.pptx
5.-Stacks.pptx5.-Stacks.pptx
5.-Stacks.pptx
 
STACKS AND QUEUES.pptx
STACKS AND QUEUES.pptxSTACKS AND QUEUES.pptx
STACKS AND QUEUES.pptx
 
STACKS AND QUEUES.pptx
STACKS AND QUEUES.pptxSTACKS AND QUEUES.pptx
STACKS AND QUEUES.pptx
 
VCE Unit 03vv.pptx
VCE Unit 03vv.pptxVCE Unit 03vv.pptx
VCE Unit 03vv.pptx
 
Stack a Data Structure
Stack a Data StructureStack a Data Structure
Stack a Data Structure
 
Queue ADT for data structure for computer
Queue ADT for data structure for computerQueue ADT for data structure for computer
Queue ADT for data structure for computer
 

More from Sunipa Bera

Constructor and Destructor
Constructor and DestructorConstructor and Destructor
Constructor and DestructorSunipa Bera
 
Proposition & Logical Operations
Proposition & Logical OperationsProposition & Logical Operations
Proposition & Logical OperationsSunipa Bera
 
Integral Calculas
Integral CalculasIntegral Calculas
Integral CalculasSunipa Bera
 
Basic concept of Engineering Mechanics
Basic concept of Engineering MechanicsBasic concept of Engineering Mechanics
Basic concept of Engineering MechanicsSunipa Bera
 
Biogeographical zones of India
Biogeographical zones of IndiaBiogeographical zones of India
Biogeographical zones of IndiaSunipa Bera
 
Operating System & Application Security
Operating System & Application SecurityOperating System & Application Security
Operating System & Application SecuritySunipa Bera
 
Types of Ecosystem
Types of EcosystemTypes of Ecosystem
Types of EcosystemSunipa Bera
 
Elementary transformation
Elementary transformationElementary transformation
Elementary transformationSunipa Bera
 
Emotional Intelligence
Emotional IntelligenceEmotional Intelligence
Emotional IntelligenceSunipa Bera
 
7 cs of effective communication
7 cs of effective communication 7 cs of effective communication
7 cs of effective communication Sunipa Bera
 
Basics of microprocessor
Basics of microprocessorBasics of microprocessor
Basics of microprocessorSunipa Bera
 
Functioning of computer
Functioning of computerFunctioning of computer
Functioning of computerSunipa Bera
 
INDIAN ISLAND STUDIES
INDIAN ISLAND STUDIESINDIAN ISLAND STUDIES
INDIAN ISLAND STUDIESSunipa Bera
 
GO GREEN - GO ECOFRIENDLY
GO GREEN - GO ECOFRIENDLYGO GREEN - GO ECOFRIENDLY
GO GREEN - GO ECOFRIENDLYSunipa Bera
 
INDIA AND HERITAGE
INDIA AND HERITAGEINDIA AND HERITAGE
INDIA AND HERITAGESunipa Bera
 
Happy birthday.rtf
Happy birthday.rtfHappy birthday.rtf
Happy birthday.rtfSunipa Bera
 

More from Sunipa Bera (20)

hackers.pptx
hackers.pptxhackers.pptx
hackers.pptx
 
System tThreats
System tThreatsSystem tThreats
System tThreats
 
Constructor and Destructor
Constructor and DestructorConstructor and Destructor
Constructor and Destructor
 
Proposition & Logical Operations
Proposition & Logical OperationsProposition & Logical Operations
Proposition & Logical Operations
 
Integral Calculas
Integral CalculasIntegral Calculas
Integral Calculas
 
Basic concept of Engineering Mechanics
Basic concept of Engineering MechanicsBasic concept of Engineering Mechanics
Basic concept of Engineering Mechanics
 
Biogeographical zones of India
Biogeographical zones of IndiaBiogeographical zones of India
Biogeographical zones of India
 
Inflation
InflationInflation
Inflation
 
Operating System & Application Security
Operating System & Application SecurityOperating System & Application Security
Operating System & Application Security
 
Types of Ecosystem
Types of EcosystemTypes of Ecosystem
Types of Ecosystem
 
Elementary transformation
Elementary transformationElementary transformation
Elementary transformation
 
Emotional Intelligence
Emotional IntelligenceEmotional Intelligence
Emotional Intelligence
 
SKYDRIVE
SKYDRIVESKYDRIVE
SKYDRIVE
 
7 cs of effective communication
7 cs of effective communication 7 cs of effective communication
7 cs of effective communication
 
Basics of microprocessor
Basics of microprocessorBasics of microprocessor
Basics of microprocessor
 
Functioning of computer
Functioning of computerFunctioning of computer
Functioning of computer
 
INDIAN ISLAND STUDIES
INDIAN ISLAND STUDIESINDIAN ISLAND STUDIES
INDIAN ISLAND STUDIES
 
GO GREEN - GO ECOFRIENDLY
GO GREEN - GO ECOFRIENDLYGO GREEN - GO ECOFRIENDLY
GO GREEN - GO ECOFRIENDLY
 
INDIA AND HERITAGE
INDIA AND HERITAGEINDIA AND HERITAGE
INDIA AND HERITAGE
 
Happy birthday.rtf
Happy birthday.rtfHappy birthday.rtf
Happy birthday.rtf
 

Recently uploaded

Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterMateoGardella
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfSanaAli374401
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...KokoStevan
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.MateoGardella
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 

Recently uploaded (20)

Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 

Ds stack & queue

  • 1. Name:-Sunipa Bera B. Tech CSE (CSF) Roll No. :-17 Subject: DS Prn No.: 190105181016 Topic:- Stack & Queue
  • 3. What is a Stack? A stack is a data structure of ordered items suc h that items can be inserted and removed only at one end. • A stack is a LIFO (Last-In/ First-Out) data structure • A stack is sometimes also called a pushdown store. • What are some applications of stacks?  Program execution  Parsing  Evaluating postfix expressions
  • 4. PUSH Place an item on the Stack PEEK Look at the item on top of the stack, but do not remove it. POP Look at the item on the stack and remove it. What can we do with Stack?
  • 5. Stacks Using a IStack  A balance of braces. - (()) balanced braces - ()(()()))) not balanced braces  How can you use Istack to check a br ace is balanced or not? Interface IStack Answer: Problem When you implement the above requirement, you ignore the implementation details of Istack. What happens if we try to pop an item off the stack when the stack is empty? This is called a stack underflow. The pop method needs some way of telling us that this has happened. In java we use the java.util.EmptyStackException Interface Istack { boolean empty(); void push(char c); char pop(); char peek(); }
  • 6. Implementing a stack using an array is fairly easy. • The bottom of the stack is at data[0] • The top of the stack is at data[numItems-1] • push onto the stack at data[numItems] • pop off of the stack at data[numItems-1] Implementing a stack using a linked list isn’t that bad either… • Store the items in the stack in a linked list • The top of the stack is the head node, the bottom of the stack is the end of the list • push by adding to the front of the list • pop by removing from the front of the list
  • 7. Reversing A Word We can use a stack to reverse the letters in a word. How? Read each letter in th e word and push it o nto the stack When you reach the end of the word, pop the letters off the stack an d print them out.
  • 8. What is a Queue? A data structure of ordered items such that item s can be inserted only at one end and removed a t the other end. e.g. A line at the supermarket • A queue is called a FIFO (First in-First out) data structure. • What are some applications of queues?  Round-robin scheduling in processors  Input/ Output processing  Queueing of packets for delivery in networks
  • 9. What we can do with Queue? These ops are called insert ant getfront in order to simplify things. Add an item to the queue. Enqueue Remove an item from the queue Dequeue
  • 10. Implementation of Queue • Just like a stack, we can implementing a queue in two ways: 1) Using an array 2). Using a linked list. Problems: Using an array to implement a queue is significantly harder than using an array to implement a stack. Why? Solution: Unlike a stack, where we add and remove at the same end, in a queue we add to one end and remove from the other. Implementing a queue using a linked list is still easy: • Front of the queue is stored as the head node of the linked list, rear of the queue is stored as the tail node. • Enqueue by adding to the end of the list • Dequeue by removing from the front of the list.
  • 11. Infographic Style Insert the title of your subtitle Here Option 1 Option 2 Option 2 Sketch of Insert Option 2 sketch of getforce  Enqueue at data[0] and shift all of the rest of the items in the array down to make room.  Dequeue from data[numItems-1] • Enqueue at data[rear+1] • Dequeue at data[front] • The rear variable always contains the index of the last item in the queue. • The front variable always contains the index of the first item in the queue. • When we reach the end of the array, wrap around to the front again. insert(Object item) { if(manyItems == 0) front = rear = 0; else rear = (rear + 1) mod size; data[rear] = item; manyItems++; } Object getFront() { answer = data[front]; front = (front + 1) mod size; manyItems--; return answer