public class ArrayBasedQueue<E> extends java.lang.Object implements QueueInterface<E>
| Modifier and Type | Field and Description |
|---|---|
private E[] |
arr |
private int |
back |
private int |
front |
private int |
size |
| Constructor and Description |
|---|
ArrayBasedQueue() |
| Modifier and Type | Method and Description |
|---|---|
private int |
decrementIndex(int index) |
E |
dequeue()
Retrieves and removes the element at the head of this queue.
|
E |
dequeue(int index)
Retrieves and removes the element at the specified index.
|
void |
enqueue(E e)
Adds the specified element into the stack if it is possible to do so immediately without
violating capacity restrictions, otherwise, throwing an IllegalStateException
if no space is currently available or NullPointerException if the specified element is null.
|
private int |
findIndex(int index) |
private int |
incrementIndex(int index) |
boolean |
isEmpty()
This method is called to determine if the queue is empty.
|
java.util.Iterator<E> |
iterator() |
E |
peek()
Retrieves, but does not remove, the head of this queue.
|
void |
removeAll()
Removes all elements from the queue.
|
int |
size()
This method is called to obtain the count of elements in the list.
|
private E[] arr
private int size
private int front
private int back
private int incrementIndex(int index)
private int decrementIndex(int index)
private int findIndex(int index)
public boolean isEmpty()
QueueInterfaceisEmpty in interface QueueInterface<E>public int size()
QueueInterfacesize in interface QueueInterface<E>public void enqueue(E e) throws java.lang.IllegalStateException, java.lang.NullPointerException
QueueInterfaceenqueue in interface QueueInterface<E>e - The element to add.java.lang.IllegalStateException - If the element cannot be added at this time due to capacity restrictions.java.lang.NullPointerException - If the specified element being added is null.public E peek()
QueueInterfacepeek in interface QueueInterface<E>public E dequeue()
QueueInterfacedequeue in interface QueueInterface<E>public E dequeue(int index) throws java.util.NoSuchElementException
QueueInterfacedequeue in interface QueueInterface<E>index - The index of the element to be removed.java.util.NoSuchElementException - If the specified index is invalid.public void removeAll()
QueueInterfaceremoveAll in interface QueueInterface<E>