Associate
- Joined
- 28 May 2008
- Posts
- 346
Last question on my uni assignment and im stuck because i missed the lecture for Z topic, wondering if any1 can help a man in trouble 
THe question asked to..Complete implementation of the LinkedQueue class presnted in the Appendix that follows, completeing methods...first, isEmpty. size and toString.
package jss2;
import jss2.exceptions.*;
public class LinkedQueue<T> implements QueueADT<T>
{
private int count;
private LinearNode<T> front, rear;
/**
* Creates an empty queue.
*/
public LinkedQueue()
{
count = 0;
front = rear = null;
}
/**
* Adds the specified element to the rear of this queue.
*
* @Param element the element to be added to the rear of this queue
*/
public void enqueue (T element)
{
LinearNode<T> node = new LinearNode<T>(element);
if (isEmpty())
front = node;
else
rear.setNext (node);
rear = node;
count++;
}
/**
* Removes the element at the front of this queue and returns a
* reference to it. Throws an EmptyCollectionException if the
* queue is empty.
*
* @return the element at the front of this queue
* @throws EmptyCollectionException if an empty collection exception
occurs
*/
public T dequeue() throws EmptyCollectionException
{
if (isEmpty())
throw new EmptyCollectionException ("queue");
T result = front.getElement();
front = front.getNext();
count--;
if (isEmpty())
rear = null;
return result;
}
Will keep working on with this myself but any help would be greatly appreciated!! Thanks

THe question asked to..Complete implementation of the LinkedQueue class presnted in the Appendix that follows, completeing methods...first, isEmpty. size and toString.
package jss2;
import jss2.exceptions.*;
public class LinkedQueue<T> implements QueueADT<T>
{
private int count;
private LinearNode<T> front, rear;
/**
* Creates an empty queue.
*/
public LinkedQueue()
{
count = 0;
front = rear = null;
}
/**
* Adds the specified element to the rear of this queue.
*
* @Param element the element to be added to the rear of this queue
*/
public void enqueue (T element)
{
LinearNode<T> node = new LinearNode<T>(element);
if (isEmpty())
front = node;
else
rear.setNext (node);
rear = node;
count++;
}
/**
* Removes the element at the front of this queue and returns a
* reference to it. Throws an EmptyCollectionException if the
* queue is empty.
*
* @return the element at the front of this queue
* @throws EmptyCollectionException if an empty collection exception
occurs
*/
public T dequeue() throws EmptyCollectionException
{
if (isEmpty())
throw new EmptyCollectionException ("queue");
T result = front.getElement();
front = front.getNext();
count--;
if (isEmpty())
rear = null;
return result;
}
Will keep working on with this myself but any help would be greatly appreciated!! Thanks