//--------------------------------------------------------------------------- // LinkedUnbndQueue.java by Dale/Joyce/Weems Chapter 5 // // Implements UnboundedQueueInterface using a linked list // AJG Version: MAJOR change *not* generic; format; protected->private //--------------------------------------------------------------------------- package ch05.queues; import support.LLNode; public class LinkedUnbndQueueFloat implements UnboundedQueueInterfaceFloat { private LLNode front; // reference to the front of this queue private LLNode rear; // reference to the rear of this queue public LinkedUnbndQueueFloat() { front = null; rear = null; } // Adds element to the rear of this queue. public void enqueue(Float element) { LLNode newNode = new LLNode(element); if (rear == null) front = newNode; else rear.setLink(newNode); rear = newNode; } // Throws QueueUnderflowException if this queue is empty; // otherwise, removes front element from this queue and returns it. public Float dequeue() { if (isEmpty()) throw new QueueUnderflowException("Helpful msg."); Float ans = front.getInfo(); front = front.getLink(); if (front == null) rear = null; return ans; } public boolean isEmpty() { return (front == null); } } // Local Variables: // compile-command: "cd ../..; javac ch05/queues/LinkedUnbndQueueFloat.java" // End: