The section provides overview on the concepts of queue and its operations along with static implementation using array. It also explains about circular queue and priority queue.
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Queue - Operations and Implementations
1. Chapter 2 (Part 2)
Queue
2.1 Introduction to Queue
Queue is a data structure in which new items are added from one
end and existing items are removed from another end. It follows
First In First Out (FIFO) principle. The end from which items
are removed is called front of the queue. The end from which
items are added is called rear of the queue.
2.2 Queue Operations
2.2.1 Enqueue
Enqueue is the operation from which an item is inserted to the
queue from the rear end. This operation is not possible in the
fully filled fixed size queue.
2.2.2 Dequeue
Dequeue is the operation from which an item is removed from
the queue from the front end. This operation is not possible in
the empty queue.
2.2.3 Example showing queue operation
3. Linear queue is a queue in which traversal through the queue is
possible only once. Once the element is deleted from a position,
no other element can be inserted at the same position. A linear
queue is called contiguous if it is implemented using array. A
linear queue is called linked if it is implemented using pointer or
dynamic memory allocation.
2.3.1 Contiguous Linear Queue (Algorithm)
2.3.1.1 Enqueue Operation
1. If (rear == N - 1)
a) display “Queue is full”
2. Else :
a) If (front == rear == -1) :
i) Set front = 0
ii) Set rear = 0
Else :
i) Set rear = rear + 1
b) Queue[rear] = item
3. Exit
2.3.1.1 Dequeue Operation
1. If (front == -1) :
a) display “Queue is empty”
4. 2. Else :
a) item = queue[front]
b) If (front == rear) :
i) Set front = -1
ii) Set rear = -1
Else :
i) Set front = front + 1
3. Exit
2.4 Circular Queue Implementation
Circular queue is a queue in which the last position is connected
to the first position and enables reusing of the position when the
item is dequeued. It is also called ‘Ring Buffer’.
2.4.1 Enqueue Operation (Algorithm)
1. If ( (front == 0 and rear == N-1) or (front == rear + 1) ) :
a) Print “Queue is full”
2. Else :
a) If (front == rear == -1) :
5. i) Set front = 0
ii) Set rear = 0
Else if (rear = N-1) :
i) Set rear = 0
Else :
i) Set rear = rear + 1
b) Queue[rear] = item
3. Exit
2.4.2 Dequeue Operation (Algorithm)
1. If (front == -1) :
a) display “Queue is empty”
2. Else :
a) item = queue[front]
b) If (front == rear) :
i) Set front = -1
ii) Set rear = -1
Else if (front == N-1) :
i) Set front = 0
Else :
i) Set front = front + 1
3. Exit
2.5 Priority Queue
Priority queue is a queue in which each item is associated with a
priority when enqueued into the queue and an item with highest
priority is dequeued from the queue. The front points to the
highest priority item. This type of queue is the extension of
general queue.