Contents    Page-10    Prev    Next    Page+10    Index   

Circular Queue using Array

We can easily keep a queue of elements in an array. This is the same as a stack, except that we remove items from the other end.

We make the array circular by assuming that index [0] follows index [n - 1].

public class CirQueue {
    private int [] queue;
    private int front;
    private int end;

    public CirQueue()
      { queue = new int[10];
        front = 0;
        end = 0; }

    public boolean empty()
    { return ( front == end ); }