Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

make LinkedDeque. java based on this information Please do not modify these pages!!!!! please help me make the classes below, please make sure

make  LinkedDeque. java based on this information

 

Please do not modify these pages!!!!!

 

please help me make the classes below, please make sure they compile with no errors, passed all sanity checks.

     LinkedDeque.java

  1. LinkedDequeTest.java (optional)
  2. RadixSort.java
  3. RadixSortMain.java

Do NoT modify these pages

 

 

Queue.java

/**   * The class defines the Queue interface   *    *    */  public interface Queue  {  /**   * The method adds the specified element to the tail/rear/last of the queue.   * @param data the element to add to the queue   */  void add(Type data);    /**   * The method removes and returns the front/head element from the queue.   * @throws EmptyCollectionException if the queue is empty.   * @return the front/head element from the queue   */  Type remove();    /**   * The method eturns the front/head element from the queue (without removing the element.   *    * @throws EmptyCollectionException if the queue is empty.   * @return the front element from the queue   */  Type peek();    /**   * The method indicates the number of elements in the queue   *    * @return the count of elements currently in the queue   */  int size();    /**   * The method checks if the queue is empty or not   *    * @return true if the queue contains no elements otherwise false   */  boolean isEmpty();    }

Deque.java

public interface Deque  extends Queue  {  /**   * The method adds element to the back   * @param data the element is added to the back   */  void addRear(Type data);    /**   * The method adds element to the front   * @param data the element is added to the front   */  void addFront(Type data);    /**   * The method removes element from the back   */  Type removeRear();    /**   * The method removes element from the front   */  Type removeFront();    /**   * The method examines element from the back   */  Type peekRear();    /**   * The method examines the element from the front   */  Type peekFront();  }      /**   * The class represents the exception when a collection is empty.      */  public class EmptyCollectionException extends RuntimeException  {  private static final long serialVersionUID = 8084488539524488189L;    /**   * The constructor sets up this exception with an appropriate message.   * @param message the error message   */  public EmptyCollectionException(final String message)  {  super(message);  }  }

LinkedQueue.java

/**   * The class defines a node-based queue.      * @param  the generic data type   */  public class LinkedQueue  implements Queue  {  /**   * The number of elements contained in the queue.   */  protected int size;    /**   * A reference to the first node in the queue. (The 'head' of the queue.)   */  protected Node head;    /**   * A reference to the last node in the queue. (The 'tail' of the queue.)   */  private Node tail;    /**   * The constructor initializes an empty queue.   */  public LinkedQueue()  {  size = 0;  head = null;  tail = null;  }    @Override  public void add(final Type theElement)  {  if (size == 0)  {  // base case when the queue is empty  head = new Node(theElement);  tail = head;  }  else  {  // regular case when the queue is not empty  tail.next = new Node(theElement);  tail = tail.next;  }  size++;  }    @Override  public Type remove()  {  if (size == 0)  throw new EmptyCollectionException("queue");    final Type returnValue = head.data;  head = head.next;  size--;  return returnValue;  }    @Override  public Type peek()  {  if (size == 0)  {  throw new EmptyCollectionException("queue");  }  return head.data;  }    @Override  public int size()  {  return size;  }    @Override  public boolean isEmpty()  {  return size == 0;  }    /**   * The method returns the linked queue in string format as below   * 

 * The format of the returned String is: Head -> 8, 6, 7, 5, 3, 0, 9  */ @Override public String toString() { if (size == 0) return "head ->"; final StringBuilder buffer = new StringBuilder(); buffer.append("head -> "); Node current = head; for (int i = 0; i < size - 1; i++) { buffer.append(current.data); buffer.append(", "); current = current.next; } buffer.append(current.data); return buffer.toString(); } /**  * The class represents a node in a singly linked structure.  *  * @author Varik Hoang &..p@uw.edu>  * @param generic data type  */ protected class Node { /**  * A reference to the next node in the linked structure.  */ protected Node next; /**  * A reference to the data element held in this node.  */ protected final Type data; /**  * The constructor initializes the node using the specified data element.  *  * @param data the data element held in this node  */ Node(final Type data) { this(data, null); } /**  * The constructor initializes the node using the specified data element and the specified next  * node.  *  * @param data the data element held in this node  * @param next the next node in the linked structure  */ Node(final Type data, final Node next) { this.data = data; this.next = next; } } }


please do sanity checks !!!

This is the link to sanity check. Please check with no errors and passed all the sanity check.

http://18.224.94.128/course/index.php?contest=52&pass=1735

the password is 202422777
 

actually please help me fix the code for the LinkedDeque.java

 

The sanity check doesn't need the private tail node on the LinkedDeque, so please help me fix them.
 
 

 

private Node tail;  public LinkedDeque()  {   super();   tail = null;  }           @Override   public void addRear(Type data)   {    if (data == null) {     throw new NullPointerException("Data cannot be null");    }    if (size == 0) {              // base case when the queue is empty      head = new Node(data);      tail = head;          } else {              tail.next = new Node(data);              tail = tail.next;          }    size++;   }   @Override   public void addFront(Type theElement)   {    if (theElement == null) {     throw new NullPointerException("Data cannot be null");    }    head = new Node(theElement, head);          if (size == 0) {              tail = head;          }          size++;   }   @Override   public Type removeRear()   {    if (size == 0) {              throw new EmptyCollectionException("deque");          } else if (size == 1) {              return remove();          } else {              Node current = head;              while (current.next != tail) {                  current = current.next;              }              Type returnValue = tail.data;              tail = current;              tail.next = null;              size--;              return returnValue;          }   }   @Override   public Type removeFront()   {    return remove();   }   @Override   public Type peekRear()   {    if (size == 0) {              throw new EmptyCollectionException("deque");          } else {              return tail.data;          }   }      @Override   public Type peekFront()   {    return peek();   }  }   

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

Step: 3

blur-text-image

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

Entrepreneurship

Authors: Andrew Zacharakis, William D Bygrave

5th Edition

1119563097, 9781119563099

More Books

Students also viewed these Databases questions