public class Queue {
    public Node first, last;

    public Queue () {
	first = null;
	last = null;
    }

    public boolean empty () {
	return first == null;
    }

    public void insert (Object obj) {
	Node node = new Node (obj, null);
	if (last != null) {
	    last.next = node;
	}
	last = node;
	if (first == null) {
	    first = last;
	}
    }

    public Object remove () {
	Node result = first;
 	if (first != null) {
	    first = first.next;
	}
	if (first == null) {
	    last = null;
	}
	return result;
    }

    public void print () {
	Node node;

	System.out.print ("(");

	// start at the beginning of the queue
	node = first;

	// traverse the queue, printing each element
	while (node != null) {
	    System.out.print (node.cargo);
	    node = node.next;
	    if (node != null) {
		System.out.print (", ");
	    }
	}
	
	System.out.println (")");
    }
}
