previous |
start
A Queue Implementation
public class Queue
{
/**
Constructs an empty queue
*/
public Queue()
{
list = new LinkedList();
}
/**
Adds an item to the tail of the queue
@param x the item to add
*/
public void add(Object x)
{
list.addLast(x);
}
/**
Removes an item from the head of the queue
@return the removed item
*/
public Object remove()
{
return list.removeFirst();
}
/**
Gets the number of items in the queue
@return the size
*/
public int size()
{
return list.size()
}
private LinkedList list;
}
previous |
start