Class Queue
java.lang.Object
|
+--Queue
- public class Queue
- extends java.lang.Object
Queue.java - a queue of Objects
Constructor Summary |
Queue()
|
Method Summary |
java.lang.Object |
dequeue()
dequeue - remove and return the head item of the
queue. |
void |
enqueue(java.lang.Object item)
enqueue - insert the given item at the queue tail. |
boolean |
isEmpty()
isEmpty - return whether or not the queue is empty |
static void |
main(java.lang.String[] args)
|
int |
size()
size - return the number of items in the queue |
static void |
test()
test - a random test harness that randomly
enqueues/dequeues a sequence of Integer objects, checking the
correctness of each dequeue result. |
java.lang.String |
toString()
toString - return a String representation of the
queue. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Queue
public Queue()
isEmpty
public boolean isEmpty()
isEmpty
- return whether or not the queue is empty
- Returns:
- a
boolean
value - whether or not the queue
is empty
enqueue
public void enqueue(java.lang.Object item)
enqueue
- insert the given item at the queue tail.
- Parameters:
item
- an Object
value
dequeue
public java.lang.Object dequeue()
dequeue
- remove and return the head item of the
queue. If the queue is empty, returns null.
- Returns:
- an
Object
value - head item of the queue,
or null if empty
size
public int size()
size
- return the number of items in the queue
- Returns:
- an
int
value - number of items in the
queue
toString
public java.lang.String toString()
toString
- return a String representation of the
queue.
- Overrides:
toString
in class java.lang.Object
- Returns:
- a
String
value
test
public static void test()
test
- a random test harness that randomly
enqueues/dequeues a sequence of Integer objects, checking the
correctness of each dequeue result.
main
public static void main(java.lang.String[] args)