Circular queue implemented in array. Always keep one node empty. head points to first element in queue. tail points to location where next element is to be inserted NOTE ALL ADDITION (including ++) is % size E.g., tail++ is understood as: tail = ( tail + 1) % size /* the data structure */ type q[size] // array int head, tail; // indexes into q[] /* initialize queue pointers */ void initialize() { head = tail = 0; } /* test for full */ boolean isFull() { return head == tail + 1; } /* test for empty */ boolean isEmpty() { return head == tail; } /* insert x at tail */ void insert(x) { if ( !isFull ) q[tail++] = x; else error(); } /* delete from head */ void type delete() { if ( !isEmpty ) return q[head++]; return error(); } /* print from head to tail */ /* note, this is not a queue operation, but is handy for debugging */ void printQueue() { if ( !isEmpty ) for (i = head; i != tail-1; i ++) print q[i]; }