コード例 #1
0
      public Object dequeue() {
        if (head == null) {
          throw new NoSuchElementException("No more elements");
        }

        Object retval = head.object;
        QNode oldHead = head;
        head = head.next;
        if (head == null) {
          tail = null;
        } else {
          oldHead.next = null;
        }
        return retval;
      }
コード例 #2
0
 public void enqueue(Object anObject) {
   if (head == null) {
     head = tail = new QNode(anObject, null);
   } else {
     tail.next = new QNode(anObject, null);
     tail = tail.next;
   }
 }