7-Queue Data Structure
7-Queue Data Structure
Programming ii
Queue data structure
1
Outline
❑ A Brief of Outline
▪ What is Queue?
▪ Examples
2
What is Queue?
❑ Definition
▪ A queue is a data structure that stores data in such a way that the element
stored first will be retrieved first
3
Applications of Queue
❑ Definition
▪ Message queuing,
▪ Computer networks
▪ etc.
4
Queue Operations
❑ Operation
▪ A queue is controlled by two main operations which implement the FIFO method
▪ Insertion
▪ Add element to the queue.
▪ Deletion enqueue()
dequeue()
▪ Remove element from the queue.
rear
front
▪ This method is called dequeue
5
Queue Operations
❑ More operations
6
Queue Implementation
❑ Definition
2. As a Linked List
Queue as Linked List
7
Disadvantage of Queue as Array
❑ Definition
For example:
➢ This queue is considered as full although there are two
empty spaces in the beginning of the queue
unused block
8
Implementing Queue as
Linked List
9
Queue Implementation
❑ Queue as a Linked List
10
Queue Implementation: Examples
❑ Queue as a Linked List
How to implement this queue?
11
Queue Implementation
❑ Queue as a Linked List
▪ Element can be only removed from the beginning of the list (dequeue operation)
Choice 2
▪ Element can be only removed from the end of the list (dequeue operation)
Remark: Choice 1 is recommended.
12
Let’s code it!
13
Practice
Using queue data structure
Create a queue that stores each letter for an English word input by a
user. Then add each letter of this word to this queue.
▪ Ask another user to input a word then test whether a word stored in this queue is the
same.
14
Q and A
15