public class ArrayQueue<T> extends AbstractQueue<T>
// Create a queue with some initial elements
Queue<Integer> a=new ArrayQueue<Integer>(1,2,3,4,5,6,7,8);
int counter=9;
// Always add one new element and poll two
while(a.size()!=0) {
a.offer(counter++);
D.p(a.poll());
D.p(a.poll());
}
-->
1,2,3,...,14
| Modifier and Type | Field and Description |
|---|---|
protected static Object[] |
blanks
Dummy blank objects used to enlarge the data array
|
protected List<T> |
data
Holds the queue elements
|
protected int |
first
Index of the first element
|
protected int |
last
Index of the last element
|
| Constructor and Description |
|---|
ArrayQueue(Collection<T> initialData) |
ArrayQueue(int size) |
ArrayQueue(T... initialData) |
| Modifier and Type | Method and Description |
|---|---|
Iterator<T> |
iterator() |
static void |
main(String[] args)
Test routine
|
boolean |
offer(T o) |
T |
peek() |
T |
poll() |
int |
size() |
contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitcontains, containsAll, equals, hashCode, isEmpty, parallelStream, remove, removeAll, removeIf, retainAll, spliterator, stream, toArray, toArrayprotected int first
protected int last
protected static Object[] blanks
public ArrayQueue(T... initialData)
public ArrayQueue(Collection<T> initialData)
public ArrayQueue(int size)
public Iterator<T> iterator()
iterator in interface Iterable<T>iterator in interface Collection<T>iterator in class AbstractCollection<T>public int size()
size in interface Collection<T>size in class AbstractCollection<T>public boolean offer(T o)
public T peek()
public T poll()
public static void main(String[] args)
Copyright © 2018. All rights reserved.