Problem Statement :
Implement Circular Queue Using Arrays
Source Code Link
Solution:
Circular Queue is efficient version of Queue, in which elements are stored efficiently without wastage of space.
The concept that circular queue uses is incrementation of the index pointer, which is achieved by
index = (index +1 )%N , this formula brings the index to start position if it crosses the end of the array.
We will be using two pointers namely "rear" and "front".
rear pointer - tracks the latest item inserted.
front pointer - tracks the oldest item in the queue.
Below is the implementation of Circular Queue.
Now given below is implementation of all the operations present in the interface.
Any improvement or suggestions for the above code are most welcome. Source Code is hosted on Ideone , please follow the link given above.
Happy Coding!! :)
Implement Circular Queue Using Arrays
Source Code Link
Solution:
Circular Queue is efficient version of Queue, in which elements are stored efficiently without wastage of space.
The concept that circular queue uses is incrementation of the index pointer, which is achieved by
index = (index +1 )%N , this formula brings the index to start position if it crosses the end of the array.
We will be using two pointers namely "rear" and "front".
rear pointer - tracks the latest item inserted.
front pointer - tracks the oldest item in the queue.
Below is the implementation of Circular Queue.
Now given below is implementation of all the operations present in the interface.
Any improvement or suggestions for the above code are most welcome. Source Code is hosted on Ideone , please follow the link given above.
Happy Coding!! :)