JavaGian java tutorial and java interview question and answer

JavaGian , Free Online Tutorials, JavaGian provides tutorials and interview questions of all technology like java tutorial, android, java frameworks, javascript, ajax, core java, sql, python, php, c language etc. for beginners and professionals.

Showing posts with label Circular-Queue. Show all posts
Showing posts with label Circular-Queue. Show all posts

Explain Circular Queue?

10:50 PM
Circular Queue Deletions and insertions can only be performed at front and rear end respectively, as far as linear queue is concerned. Consider the queue shown in the following figure.   The Queue shown in above figure is completely filled and there can't be inserted any more element due to the condition  rear == max - 1 becomes true . However, if we delete 2 elements at the front end of the queue, we still can not insert any element since the condition  rear = max -1 still holds . This is the main problem with the linear queue, although we have space available in the array, but we can not insert any more element in the queue. This is simply the memory wastage and we need to overcome this problem.   One of the solution of this problem is circular queue. In the circular queue, the first index comes right after the last index. You can think of a circular queue as shown in the following figure.   Circular queue will be full when  front = -1  and  rear = max-1 . Impl

.