Solution:-
Introduction of Queue:-
* Queue is Linear , Non – primitive data structure.
* Accessed from two ends
i. Rear -> To insert item
ii. Front -> To delete item
* Queue operations are:
i. Insertion (enque)
ii. Deletion (deque)
* Working principles First in First out (FIFO).
Algorithm:-
Algorithm to insert item in to linear queue (enque )
enque ( queue [maxsize] , item , rear , front )
Step 1:- if (rear == maxsize -1)
print " QUEUE OVERFLOW "
Other wise
Read item
if ( front = = rear = = -1)
Set rear = 0
Set front = 0
Other wise
Set rear = rear + 1
End if
Set queue[rear]=item
print " SUCCESS INSERT ITEM "
End if
Step 2:- stop.
Algorithm to delete item from linear queue ( deque )
Deque (queue [maxsize ] , item , front , rear )
Step 1:- if( front == -1 )
print " QUEUE UNDERFLOW "
Otherwise
Set item = queue [front]
if( rear == front )
Set front = -1
Set rear = -1
Otherwise
Set front = front +1
End if
print " SUCCESS DELETE ITEM "
End if
Step 2:- stop.
Introduction of Queue:-
* Queue is Linear , Non – primitive data structure.
* Accessed from two ends
i. Rear -> To insert item
ii. Front -> To delete item
* Queue operations are:
i. Insertion (enque)
ii. Deletion (deque)
* Working principles First in First out (FIFO).
Algorithm:-
Algorithm to insert item in to linear queue (enque )
enque ( queue [maxsize] , item , rear , front )
Step 1:- if (rear == maxsize -1)
print " QUEUE OVERFLOW "
Other wise
Read item
if ( front = = rear = = -1)
Set rear = 0
Set front = 0
Other wise
Set rear = rear + 1
End if
Set queue[rear]=item
print " SUCCESS INSERT ITEM "
End if
Step 2:- stop.
Algorithm to delete item from linear queue ( deque )
Deque (queue [maxsize ] , item , front , rear )
Step 1:- if( front == -1 )
print " QUEUE UNDERFLOW "
Otherwise
Set item = queue [front]
if( rear == front )
Set front = -1
Set rear = -1
Otherwise
Set front = front +1
End if
print " SUCCESS DELETE ITEM "
End if
Step 2:- stop.