What Linear Queue?
It is a linear data structure.
It supports FIFO (First In First Out) property.
It is considered a sequence of items.
It has three components:
- A Container of items that contain elements of a queue.
- A pointer front that points to the first item of the queue.
- A pointer rear that points to the last item of the queue.
Insertion is performed from REAR end.
Deletion is performed from FRONT end.
Insertion operation is also known as ENQUEUE in queue.
There are five operations:
- Initialization.
- Addition or insertion.
- Deletion.
- Is_full check.
- Is_empty check.
There are five types of implementation :
- INIT(QUEUE,FRONT,REAR)
- INSERT-ITEM(QUEUE,FRONT,REAR,MAX,ITEM)
- REMOVE-ITEM(QUEUE,FRONT,REAR,ITEM)
- FULL-CHECK(QUEUE,FRONT,REAR,MAX,FULL)
- EMPTY-CHECK(QUEUE,FRONT,REAR,EMPTY)
INIT(QUEUE,FRONT,REAR)
This algorithm is used to initialize a QUEUE, FRONT,
and REAR.
1. FRONT := 1;
2. REAR := 0;
3. Return;
-----------------------------------------------
INSERT-ITEM(QUEUE,FRONT,REAR,MAX,ITEM)
This algorithm is used to add or insert items to QUEUE.
1. If (REAR = MAX) then
a. Display “Queue overflow”;
b. Return;
2. Otherwise
a. REAR := REAR + 1;
b. QUEUE(REAR) := ITEM;
3. Return;
--------------------------------------------
REMOVE-ITEM(QUEUE,FRONT,REAR,ITEM)
This algorithm is used to delete an item from QUEUE.
1. If (FRONT = REAR + 1) then
a. Display “Queue underflow”;
b. Return;
2. Otherwise
a. ITEM := QUEUE(FRONT);
b. FRONT := FRONT + 1;
3. Return;
EMPTY-CHECK(QUEUE,FRONT,REAR,EMPTY)
This algorithm is used to check whether
a QUEUE is EMPTY or not.
1. If (FRONT = REAR + 1) then
a. EMPTY := true;
2. Otherwise
a. EMPTY := false;
3. Return;
FULL-CHECK(QUEUE,FRONT,REAR,MAX,FULL)
This algorithm is used to check whether
a QUEUE is full or not.
1. If ( REAR = MAX ) then
a. FULL := true;
2. Otherwise
a. FULL := false;
3. Return;
output:
0 Comments