Professional Documents
Culture Documents
4 2 (Queue)
4 2 (Queue)
Daw Su Su Win
Lecturer
1
Lecture Objectives FCS
Definition
-queue is a linear data structure type which is used to organized the data.
- It is used for temporary storage of the data values.
- A new element is added at one end called rear.
- The existing element deleted from the other end is called front.
- First-in-First-Out(FIFO) property
Working of Queue
Queue operations work as follows:
two pointers FRONT and REAR
FRONT track the first element of the queue
REAR track the last element of the queue
initially, set value of FRONT and REAR to -1
• In a linked queue, each node of the queue consists of two parts i.e. data part and the link part. Each
element of the queue points to its immediate next element in the memory.
• In the linked queue, there are two pointers maintained in the memory i.e. front pointer and rear
pointer. The front pointer contains the address of the starting element of the queue while the rear
pointer contains the address of the last element of the queue.
1.Simple Queue-Simple queue defines the simple operation of queue in which insertion occurs at the rear of the list
and deletion occurs at the front of the list.
Dequeue/delete Enqueue/insert
Front Rear
7 2 6 9 1
- a circular queue, the elements act like circular rings. The working of a circular queue is similar to a
simple queue but in a circular queue, the element in the last position is connected to the element in the
first position. The main advantage of a circular queue is that the memory will be utilized in a better way.
Fig: (a) ascending order priority queue Fig: (b)descending order priority queue
4.Double-Ended Queue(Deque) FCS
• The major drawback of using a linear Queue is that insertion is done only from the rear end.
If the first three elements are deleted from the Queue, we cannot insert more elements even
though the space is available in a Linear Queue. In this case, the linear Queue shows the
overflow condition as the rear is pointing to the last element of the Queue.
Resolving Drawback
• The drawback that occurs in a linear queue is overcome by using the circular queue. If the
empty space is available in a circular queue, the new element can be added in an empty
space by simply incrementing the value of rear. The main advantage of using the circular
queue is better memory utilization.
14
Enqueue Operation / Insertion FCS
Queue Operations and Specifications
rear is pointing.
Rear Front
D
C B A Before
Rear Front
D C B A After
• Step 3 − If the queue is not empty, access the data where front is pointing.
• Step 4 −Increment front pointer to point to the next available data element.
Rear Front
Before D C B A
Rear Front
After D C B dequeue
Queue
A
Figure 2: Operation in Dequeue
A Linear data structure that stores data as a A linear data structure in which the last item
sequence of element similar to a real world connects back to the first item forming a circle.
queue. Possible to enter and removes element from any
Possible to enter new items from the rear end position.
and remove the items from the front. Requires less memory.
Requires more memory. More efficient.
Less efficient.
• Firt Ins First Out (FIFO) data structure Implemented as array or linked listLinked
lists: queue
• Types of queue
• Application in Queue
1. A list structure with two access points called the front and rear.
4. Homogeneous components