Part-1(Java) Create a doubly linked list based DeQueDLL class that implements the DequeInterface. The class skeleton and interface are provided to you. Implement a String toString () method that creates and returns a string that correctly represents the current deque. Such a method could prove useful for testing and debugging the class and for testing and debugging applications that use the class. Assume each queued element already provides its own reasonable toString method. Skeleton: import ch04.queues.*;import support.DLLNode; public class DeQueDLL<T> implements DequeInterface<T> {protected DLLNode<T> front, rear; // reference to the front and rear of this dequeprotected int numElements = 0; // number of elements in this deque public DeQueDLL() {front = null;rear = null;} public void enqueueFront(T element) {// TODO Auto-generated method stub} public void enqueueRear(T element) {// TODO Auto-generated method stub} public T dequeueFront() throws QueueUnderflowException {// TODO Auto-generated method stubreturn null;} public T dequeueRear() throws QueueUnderflowException {// TODO Auto-generated method stubreturn null;} public boolean isFull() {// TODO Auto-generated method stubreturn false;} public boolean isEmpty() {// TODO Auto-generated method stubreturn false;} public int size() {// TODO Auto-generated method stubreturn 0;} } import ch04.queues.QueueOverflowException;import ch04.queues.QueueUnderflowException; public interface DequeInterface<T>{void enqueueFront(T element) throws QueueOverflowException;// Throws QueueOverflowException if this queue is full;// otherwise, adds element to the front of this queue. void enqueueRear(T element) throws QueueOverflowException;// Throws QueueOverflowException if this queue is full;// otherwise, adds element to the rear of this queue. T dequeueFront() throws QueueUnderflowException;// Throws QueueUnderflowException if this queue is empty;// otherwise, removes front element from this queue and returns it. T dequeueRear() throws QueueUnderflowException;// Throws QueueUnderflowException if this queue is empty;// otherwise, removes rear element from this queue and returns it. boolean isFull();// Returns true if this queue is full; otherwise, returns false. boolean isEmpty();// Returns true if this queue is empty; otherwise, returns false.int size();// Returns the number of elements in this queue. }
Types of Linked List
A sequence of data elements connected through links is called a linked list (LL). The elements of a linked list are nodes containing data and a reference to the next node in the list. In a linked list, the elements are stored in a non-contiguous manner and the linear order in maintained by means of a pointer associated with each node in the list which is used to point to the subsequent node in the list.
Linked List
When a set of items is organized sequentially, it is termed as list. Linked list is a list whose order is given by links from one item to the next. It contains a link to the structure containing the next item so we can say that it is a completely different way to represent a list. In linked list, each structure of the list is known as node and it consists of two fields (one for containing the item and other one is for containing the next item address).
Part-1(Java)
- Create a doubly linked list based DeQueDLL class that implements the DequeInterface. The class skeleton and interface are provided to you.
- Implement a String toString () method that creates and returns a string that correctly represents the current deque. Such a method could prove useful for testing and debugging the class and for testing and debugging applications that use the class. Assume each queued element already provides its own reasonable toString method.
Skeleton:
import ch04.queues.*;
import support.DLLNode;
public class DeQueDLL<T> implements DequeInterface<T> {
protected DLLNode<T> front, rear; // reference to the front and rear of this deque
protected int numElements = 0; // number of elements in this deque
public DeQueDLL() {
front = null;
rear = null;
}
public void enqueueFront(T element) {
// TODO Auto-generated method stub
}
public void enqueueRear(T element) {
// TODO Auto-generated method stub
}
public T dequeueFront() throws QueueUnderflowException {
// TODO Auto-generated method stub
return null;
}
public T dequeueRear() throws QueueUnderflowException {
// TODO Auto-generated method stub
return null;
}
public boolean isFull() {
// TODO Auto-generated method stub
return false;
}
public boolean isEmpty() {
// TODO Auto-generated method stub
return false;
}
public int size() {
// TODO Auto-generated method stub
return 0;
}
}
import ch04.queues.QueueOverflowException;
import ch04.queues.QueueUnderflowException;
public interface DequeInterface<T>
{
void enqueueFront(T element) throws QueueOverflowException;
// Throws QueueOverflowException if this queue is full;
// otherwise, adds element to the front of this queue.
void enqueueRear(T element) throws QueueOverflowException;
// Throws QueueOverflowException if this queue is full;
// otherwise, adds element to the rear of this queue.
T dequeueFront() throws QueueUnderflowException;
// Throws QueueUnderflowException if this queue is empty;
// otherwise, removes front element from this queue and returns it.
T dequeueRear() throws QueueUnderflowException;
// Throws QueueUnderflowException if this queue is empty;
// otherwise, removes rear element from this queue and returns it.
boolean isFull();
// Returns true if this queue is full; otherwise, returns false.
boolean isEmpty();
// Returns true if this queue is empty; otherwise, returns false.
int size();
// Returns the number of elements in this queue.
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps