disadvantages of linear queue how it is solved over circular queue
Answers
Answered by
45
Disadvantage of Linear/Static Queue-
When any element is inserted in linear queue then rear will be increased by 1. Let, assume after insertion operations rear is shifted to last position in queue. It means, now queue is full. Now if a new element is inserted then overflow condition will occur.
To convert static/linear queue into circular queue:-
circular queue is a special type of queue in which last position and first position are assumed as adjacent position. It means in circular queue first position after last position. If front=0 and rear=N-1 or front=rear+1, then circular queue is full and we can't perform insertion of new element and overflow condition will occur. If rear=N-1 and front is not equal to 0, then we set rear=0 for insertion of new element. If first element is inserted in queue then front=rear=-1 will be set on front=rear=0. Otherwise, rear will be increased by 1.
When any element is inserted in linear queue then rear will be increased by 1. Let, assume after insertion operations rear is shifted to last position in queue. It means, now queue is full. Now if a new element is inserted then overflow condition will occur.
To convert static/linear queue into circular queue:-
circular queue is a special type of queue in which last position and first position are assumed as adjacent position. It means in circular queue first position after last position. If front=0 and rear=N-1 or front=rear+1, then circular queue is full and we can't perform insertion of new element and overflow condition will occur. If rear=N-1 and front is not equal to 0, then we set rear=0 for insertion of new element. If first element is inserted in queue then front=rear=-1 will be set on front=rear=0. Otherwise, rear will be increased by 1.
Similar questions