4import java.util.NoSuchElementException;
18 static final int DEFAULT_SIZE = 16;
25 @SuppressWarnings(
"unchecked")
28 data_=(T[])
new Object[capacity];
44 throw new NoSuchElementException();
52 throw new NoSuchElementException();
55 head_=(head_+1)%data_.length;
63 int newtail=(tail_+1)%data_.length;
89 assert(head_==0 && tail_<data_.length);
158 int t=(tail_+data_.length-1)%data_.length;
163 t=(t+data_.length-1)%data_.length;
Implementation of AbstractQueue as a (dynamically resized) circular buffer based on array.
void enqueue(T x)
Enqueue element at end of queue.
boolean is_empty()
Is queue empty?
String toString()
Get string representation.
T dequeue()
Remove front element from queue.
Queue()
create empty queue
T front()
Get front element of queue.
Interface for an ADT queue.
AuD lecture: Data structures, algorithms, examples.