Question: Code 1 /** * * 2 D * */ public class CircularDoublyLinkedDeque implements DequeInterface { private DLNode firstNode; public CircularDoublyLinkedDeque() { } public void addToBack(T

 Code 1 /** * * 2 D * */ public class

Code 1

/**

*

* 2 D

*

*/

public class CircularDoublyLinkedDeque implements DequeInterface

{

private DLNode firstNode;

public CircularDoublyLinkedDeque()

{

}

public void addToBack(T newEntry)

{

}

public void addToFront(T newEntry)

{

}

public T getFront()

{

}

public T getBack()

{

}

public T removeFront()

{

}

public T removeBack()

{

}

public void clear()

{

}

public boolean isEmpty()

{

}

/**

* class DLNode

* You do not need to change any code in class DLNode

*

*/

private class DLNode

{

private T data; // Deque entry

private DLNode next; // Link to next node

private DLNode previous; // Link to previous node

private DLNode()

{

this(null, null, null);

} // end default constructor

private DLNode(T dataPortion)

{

this(null, dataPortion, null);

} // end constructor

private DLNode(DLNode previousNode, T dataPortion, DLNode nextNode)

{

data = dataPortion;

next = nextNode;

previous = previousNode;

} // end constructor

private T getData()

{

return data;

} // end getData

private void setData(T newData)

{

data = newData;

} // end setData

private DLNode getNextNode()

{

return next;

} // end getNextNode

private void setNextNode(DLNode nextNode)

{

next = nextNode;

} // end setNextNode

private DLNode getPreviousNode()

{

return previous;

} // end getPreviousNode

private void setPreviousNode(DLNode previousNode)

{

previous = previousNode;

} // end setPreviousNode

} // end DLNode

} // end CircularDoublyLinkedDeque

Code 2

/**

*

* 2 D

* You do not need to change any code in interface DequeInterface

*

*/

public interface DequeInterface

{

/** Adds a new entry to the front/back of this dequeue.

@param newEntry An object to be added. */

public void addToFront(T newEntry);

public void addToBack(T newEntry);

/** Removes and returns the front/back entry of this dequeue.

@return The object at the front/back of the dequeue.

@throws EmptyQueueException if the dequeue is empty before the operation. */

public T removeFront();

public T removeBack();

/** Retrieves the front/back entry of this dequeue.

@return The object at the front/back of the dequeue.

@throws EmptyQueueException if the dequeue is empty before the operation. */

public T getFront();

public T getBack();

/** Detects whether this dequeue is empty.

@return True if the queue is empty, or false otherwise. */

public boolean isEmpty();

/** Removes all entries from this dequeue. */

public void clear();

} // end DequeInterface

Code 3

/**

*

* 2 D

* You do not need to change any code in class Driver

*

*/

public class Driver

{

public static void main(String[] args)

{

System.out.println("Create a deque: ");

DequeInterface myDeque = new CircularDoublyLinkedDeque();

System.out.println(" isEmpty() returns " + myDeque.isEmpty() + " ");

System.out.println("Add to front and back of deque to get " +

"Joe Jess Jim Jill Jane Jerry ");

myDeque.addToFront("Jim");

myDeque.addToFront("Jess");

myDeque.addToBack("Jill");

myDeque.addToBack("Jane");

myDeque.addToFront("Joe");

myDeque.addToBack("Jerry");

System.out.println(" isEmpty() returns " + myDeque.isEmpty() + " ");

System.out.println(" Testing getFront, getBack, removeFront, removeBack: ");

String front, back;

front = myDeque.getFront();

System.out.println(front + " is at the front of the deque.");

back = myDeque.getBack();

System.out.println(back + " is at the back of the deque.");

front = myDeque.removeFront();

System.out.println(front + " is removed from the front of the deque.");

back = myDeque.removeBack();

System.out.println(back + " is removed from the back of the deque.");

front = myDeque.getFront();

System.out.println(front + " is at the front of the deque.");

back = myDeque.getBack();

System.out.println(back + " is at the back of the deque.");

System.out.println(" Testing clear: ");

myDeque.clear();

System.out.println(" isEmpty() returns " + myDeque.isEmpty() + " ");

try

{

front = myDeque.removeFront();

System.out.println("removeFront incorrectly finds queue not empty");

} // end try

catch (EmptyQueueException e)

{

System.out.println("removeFront correctly finds deque empty");

} // end catch

try

{

front = myDeque.removeBack();

System.out.println("removeBack incorrectly finds queue not empty");

} // end try

catch (EmptyQueueException e)

{

System.out.println("removeBack correctly finds deque empty");

} // end catch

System.out.println(" Done.");

} // end main

} // end Driver

Code 4

/**

*

* 2 D

* You do not need to change any code in class EmptyQueueException

*

*/

public class EmptyQueueException extends RuntimeException

{

public EmptyQueueException()

{

this(null);

} // end default constructor

public EmptyQueueException(String message)

{

super(message);

} // end constructor

} // end EmptyQueueExcept

myPriorityQueue.add(myPriorityQueue.peek(); run: myPriorityQueue.add("Jim"); Create a deque: myPriorityQueue.removel); isEmpty () returns true D. -- 12 points -- Use a circular doubly linked chain to implement the ADT deque. Add to front and back of deque to get Joe Jess Jim Jill Jane Jerry isEmpty () returns false In a doubly linked chain, the first and last nodes each contain one null reference, since the first node has no previous node and the last node has no node after it. In a circular doubly linked chain, the first node references the last node, and the last node references the first. Only one external reference is necessarya reference to the first node since you can quickly get to the last node from the first node. Testing getFront, getBack, removeFront , removeBack: The code for this problem is provided in the Assignment-03-Code.zip archive. Your output must be identical to the output to the right. Joe is at the front of the deque. Jerry is at the back of the deque . Joe is removed from the front of the deque. Jerry is removed from the back of the deque. Jess is at the front of the deque. Jane is at the back of the deque. Testing clear: myPriorityQueue.add(myPriorityQueue.peek(); run: myPriorityQueue.add("Jim"); Create a deque: myPriorityQueue.removel); isEmpty () returns true D. -- 12 points -- Use a circular doubly linked chain to implement the ADT deque. Add to front and back of deque to get Joe Jess Jim Jill Jane Jerry isEmpty () returns false In a doubly linked chain, the first and last nodes each contain one null reference, since the first node has no previous node and the last node has no node after it. In a circular doubly linked chain, the first node references the last node, and the last node references the first. Only one external reference is necessarya reference to the first node since you can quickly get to the last node from the first node. Testing getFront, getBack, removeFront , removeBack: The code for this problem is provided in the Assignment-03-Code.zip archive. Your output must be identical to the output to the right. Joe is at the front of the deque. Jerry is at the back of the deque . Joe is removed from the front of the deque. Jerry is removed from the back of the deque. Jess is at the front of the deque. Jane is at the back of the deque. Testing clear

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!