Linear or simple queue:-
A linear queue is just like a stack. But unlike a stack, a linear queue is open from both the ends. But it's both ends are not use for both the operation insertion(enqueue) and deletion(dequeue) rather from one end insertion takes place and from the other hand deletion takes place.
The end from where insertion takes place is called rear and the end from where deletion takes place is called front.
Moreover since a linear queue uses both the opposite ends for insertion and deletion. In other words, we say that it is based on the principle of First in first out(FIFO).
Example:-
Note:- If queue is an empty than rear points at -1 index position and front points at 0 index position.
Pseudocode for insertion(enqueue) in a Linear or simple queue:-
Enqueue operation of a queue involves a series of steps-
step 1- Check whether the queue is full or not.
step 2- If queue is full then print the message "queue overflow" and return.
step 3- If queue is not full then increment rear by one.
step 4- Place the element in the queue at the position where rear is pointing.
step 5- finish and return.
Pseudocode for deletion(dequeue) in a Linear or simple queue:-
Dequeue operation of a queue involves a series of steps-
step 1- Check whether the queue is empty or not.
step 2- If queue is empty then print the message "queue underflow" and return.
step 3- If queue is not empty then remove the element from the queue at which front is pointing.
step 4- Increment the value of front by one.
step 5- Return the deleted element.
Implementation of a Linear queue in C language:-
Output:-
Implementation of a Linear queue in Java:-
Output:-
also see:-
Drawbacks of a Linear queue
A linear queue is just like a stack. But unlike a stack, a linear queue is open from both the ends. But it's both ends are not use for both the operation insertion(enqueue) and deletion(dequeue) rather from one end insertion takes place and from the other hand deletion takes place.
The end from where insertion takes place is called rear and the end from where deletion takes place is called front.
Moreover since a linear queue uses both the opposite ends for insertion and deletion. In other words, we say that it is based on the principle of First in first out(FIFO).
Example:-
Note:- If queue is an empty than rear points at -1 index position and front points at 0 index position.
Pseudocode for insertion(enqueue) in a Linear or simple queue:-
Enqueue operation of a queue involves a series of steps-
step 1- Check whether the queue is full or not.
step 2- If queue is full then print the message "queue overflow" and return.
step 3- If queue is not full then increment rear by one.
step 4- Place the element in the queue at the position where rear is pointing.
step 5- finish and return.
Pseudocode for deletion(dequeue) in a Linear or simple queue:-
Dequeue operation of a queue involves a series of steps-
step 1- Check whether the queue is empty or not.
step 2- If queue is empty then print the message "queue underflow" and return.
step 3- If queue is not empty then remove the element from the queue at which front is pointing.
step 4- Increment the value of front by one.
step 5- Return the deleted element.
Implementation of a Linear queue in C language:-
Output:-
Implementation of a Linear queue in Java:-
Output:-
also see:-
Drawbacks of a Linear queue
0 Comments