Currently, this is what I h ave for my list implementation. It's supposed to be a circular linked list queue with a single variable (rear) identifying the end of the queue. I keep getting null pointer exceptions when my programs hits the "dequeue" so I assume it's somewhere in there. Again, I'm not sure how these are implemented in terms of coding, and if additional information (i.e. what the interface it's extending looks like etc) let me know.
public class CircLinkedUnbndQueue implements UnboundedQueueInterface
{
protected LLObjectNode rear; // reference to the rear of this queue
public CircLinkedUnbndQueue()
{
rear = null;
}
public void enqueue(Object element)
// Adds element to the rear of this queue.
{
LLObjectNode newNode = new LLObjectNode(element);
if (rear == null)
rear = newNode;
else
rear.setLink(newNode);
rear = newNode;
}
public Object dequeue()
// Throws QueueUnderflowException if this queue is empty;
// otherwise, removes front element from this queue and returns it.
{
Object element;
element = rear.getInfo();
rear = rear.getLink();
if (rear == null)
rear = null;
return element;
}
public boolean isEmpty()
// Returns true if this queue is empty; otherwise, returns false.
{
if (rear == null)
return true;
else
return false;
}
}

New Topic/Question
Reply




MultiQuote






|