Package dsa.lab03.exercises
Class ArrayQueue<Item>
java.lang.Object
dsa.lab03.exercises.ArrayQueue<Item>
- Type Parameters:
Item
- the item type
An array queue.
Implements the queue interface by using a circular dynamic array.
-
Constructor Summary
ConstructorDescriptionConstruct an empty array queue.ArrayQueue
(Item... items) Construct an array queue containing the given items.ArrayQueue
(Iterable<Item> items) Construct an array queue containing the given items.ArrayQueue
(Iterable<Item> items, int size) Construct an array queue containing the given items more efficiently thanArrayQueue(Iterable)
. -
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
ArrayQueue
public ArrayQueue()Construct an empty array queue. -
ArrayQueue
Construct an array queue containing the given items.- Parameters:
items
- the items
-
ArrayQueue
Construct an array queue containing the given items more efficiently thanArrayQueue(Iterable)
.- Parameters:
items
- the itemssize
- the number of items- Throws:
IllegalArgumentException
- ifsize
!=n
(wheren
isitems
's size)
-
ArrayQueue
Construct an array queue containing the given items.- Parameters:
items
- the items
-
-
Method Details
-
enqueue
Description copied from interface:Queue
Enqueue (insert) the given item to the back. -
dequeue
Description copied from interface:Queue
Dequeue (remove and return) the given item from the front.- Specified by:
dequeue
in interfaceQueue<Item>
- Returns:
- the old front item
- Throws:
NoSuchElementException
- if there's no first item to remove (i.e. if this is empty)
-
front
Description copied from interface:Queue
Get the item at the front.- Specified by:
front
in interfaceQueue<Item>
- Returns:
- the front item
- Throws:
NoSuchElementException
- if there's no first item to retrieve (i.e. if this is empty)
-
size
public int size()Description copied from interface:Container
Get the number of contained items. -
items
Description copied from interface:Container
Get an iterable that yields each item once.
-