Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Everything works except for list. I need help implementing it in LinkedQueue.java LinkedQueue.java package jsjf; import jsjf.exceptions.*; /** * LinkedQueue represents a linked implementation of

Everything works except for list. I need help implementing it in LinkedQueue.java

LinkedQueue.java

package jsjf;

import jsjf.exceptions.*;

/** * LinkedQueue represents a linked implementation of a queue. * * @author Java Foundations * @version 4.0 */ public class LinkedQueue implements QueueADT { private int count; private LinearNode head, tail;

/** * Creates an empty queue. */ public LinkedQueue() { count = 0; head = tail = null; } /** * Adds the specified element to the tail of this queue. * @param element the element to be added to the tail of the queue */ public void enqueue(T element) { LinearNode node = new LinearNode(element);

if (isEmpty()) head = node; else tail.setNext(node);

tail = node; count++; } /** * Removes the element at the head of this queue and returns a * reference to it. * @return the element at the head of this queue * @throws EmptyCollectionException if the queue is empty */ public T dequeue() throws EmptyCollectionException { if (isEmpty()) //if the queue is empty, the message is printed out. { System.out.println("Queue is empty. Please enqueue at least 1 element first."); tail = null; } else { T result = head.getElement(); head = head.getNext(); count--; return result; } return null; } /** * Returns a reference to the element at the head of this queue. * The element is not removed from the queue. * @return a reference to the first element in this queue * @throws EmptyCollectionsException if the queue is empty */ public T first() throws EmptyCollectionException { if (isEmpty()) { System.out.println("Queue is empty. Please enqueue at least 1 element first."); } else { T result = head.getElement();

return result; } return null; }

/** * Returns true if this queue is empty and false otherwise. * @return true if this queue is empty */ public boolean isEmpty() { return (count==0); }

/** * Returns the number of elements currently in this queue. * @return the number of elements in the queue */ public int size() { return count; }

/** * Returns a string representation of this queue. * @return the string representation of the queue */ public String toString() { String result = "";

LinearNodex = head;

while(x != null) { result += x.getElement().toString() + " "; x = x.getNext(); } return result; }

public void list() { //Need help here } }

QueueADT.java

package jsjf;

/** * QueueADT defines the interface to a queue collection. * * @author Java Foundation * @version 4.0 */ public interface QueueADT { /** * Adds one element to the rear of this queue. * @param element the element to be added to the rear of the queue */ public void enqueue(T element);

/** * Removes and returns the element at the front of this queue. * @return the element at the front of the queue */ public T dequeue();

/** * Returns without removing the element at the front of this queue. * @return the first element in the queue */ public T first();

/** * Returns true if this queue contains no elements. * @return true if this queue is empty */ public boolean isEmpty();

/** * Returns the number of elements in this queue. * @return the integer representation of the size of the queue */ public int size();

/** * Returns a string representation of this queue. * @return the string representation of the queue */ public String toString(); public void list(); }

LinearNode.java

package jsjf;

/** * Represents a node in a linked list. * * @author Java Foundations * @version 4.0 */ public class LinearNode { private LinearNode next; private T element;

/** * Creates an empty node. */ public LinearNode() { next = null; element = null; }

/** * Creates a node storing the specified element. * @param elem element to be stored */ public LinearNode(T elem) { next = null; element = elem; }

/** * Returns the node that follows this one. * @return reference to next node */ public LinearNode getNext() { return next; }

/** * Sets the node that follows this one. * @param node node to follow this one */ public void setNext(LinearNode node) { next = node; }

/** * Returns the element stored in this node. * @return element stored at the node */ public T getElement() { return element; }

/** * Sets the element stored in this node. * @param elem element to be stored at this node */ public void setElement(T elem) { element = elem; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Filing And Computer Database Projects

Authors: Jeffrey Stewart

2nd Edition

007822781X, 9780078227813

More Books

Students also viewed these Databases questions

Question

Provide the best employee relations environment.

Answered: 1 week ago

Question

Describe the strategic training and development process.

Answered: 1 week ago

Question

Complexity of linear search is O ( n ) . Your answer: True False

Answered: 1 week ago

Question

What does Processing of an OLAP Cube accomplish?

Answered: 1 week ago