Circular queue in Data Structure
The queue that we implemented using an array suffers from one limitation. In that implementation there is a possibility that the queue is reported as full (since rear has reached the end of the array), even though in actuality there might be empty slots at the beginning of the queue. To overcome this limitation we can implement the queue as a circular queue . Here as we go on adding elements to the queue and reach the end of the array, the next element is stored in the first slot of the array (provided it is free).
More clearly, suppose an array arr of n elements is used to implement a circular queue. Now if we go on adding elements to the queue we may reach arr(n-l). We cannot add any more elements to the queue since we have reached the end of the an-ay. Instead of reporting the queue as full, if some elements in the queue have been deleted then there might be empty slots at the beginning of the queue. In such a case these slots would be filled by new elements being added to the queue. In short just because we have reached the end of the array the queue would not be reported as full. The queue would be reported as full only when all the slots in the array stand occupied.
No comments:
Post a Comment