Question: DEQUE.JAVA import java.util.NoSuchElementException; /** * Deque defines the interface to a deque ADT. * * @author Acuna, Lewis et al. * @version 1.0 * @param


DEQUE.JAVA
import java.util.NoSuchElementException; /** * Deque defines the interface to a deque ADT. * * @author Acuna, Lewis et al. * @version 1.0 * @param- contained type */ public interface Deque
- { /** * Adds one element to the front of this deque. * @param element the element to be added to the front of the deque */ public void enqueueFront(Item element); /** * Adds one element to the back of this deque. * @param element the element to be added to the back of the deque */ public void enqueueBack(Item element); /** * Removes and returns the element at the front of this deque. * Throws an exception if the deque is empty. * @return the element at the front of this deque * @throws NoSuchElementException if the deque is empty */ public Item dequeueFront() throws NoSuchElementException; /** * Removes and returns the element at the back of this deque. * Throw an exception if the deque is empty. * @return the element at the back of the deque. * @throws NoSuchElementException if the deque is empty */ public Item dequeueBack() throws NoSuchElementException; /** * Returns, without removing, the element at the front of this deque. * Should throw an exception if the deque is empty. * @return the first element in the deque * @throws NoSuchElementException if the deque is empty */ public Item first() throws NoSuchElementException; /** * Returns, without removing, the element at the back of this deque. * Should throw an exception if the deque is empty. * @return the last element in the deque * @throws NoSuchElementException if the deque is empty */ public Item last() throws NoSuchElementException; /** * Returns true if this deque is empty and false otherwise. * @return if deque empty */ public boolean isEmpty(); /** * Returns the number of elements in this deque. * @return the number of elements in the deque */ public int size(); /** * Returns a string representation of this deque. The back element * occurs first, and each element is separated by a space. If the * deque is empty, returns "empty". * @return the string representation of the deque */ @Override public String toString(); }
BASEDEQUE.JAVA
/** * This program provides an implementation of the Deque interface * and demonstrates it. * * @author (your name), Acuna * @version (version) */ import java.util.NoSuchElementException; //TODO: implement. public class BaseDeque- implements Deque
- { /** * Program entry point for deque. * @param args command line arguments */ public static void main(String[] args) { BaseDeque
deque = new BaseDeque(); //standard queue behavior deque.enqueueBack(3); deque.enqueueBack(7); deque.enqueueBack(4); deque.dequeueFront(); deque.enqueueBack(9); deque.enqueueBack(8); deque.dequeueFront(); System.out.println("size: " + deque.size()); System.out.println("contents: " + deque.toString()); //deque features System.out.println(deque.dequeueFront()); deque.enqueueFront(1); deque.enqueueFront(11); deque.enqueueFront(3); deque.enqueueFront(5); System.out.println(deque.dequeueBack()); System.out.println(deque.dequeueBack()); System.out.println(deque.last()); deque.dequeueFront(); deque.dequeueFront(); System.out.println(deque.first()); System.out.println("size: " + deque.size()); System.out.println("contents: " + deque.toString()); } }
For this assignment, you will practice writing a deque ADT (i.e., LastnameDeque). A deque is closely related to a queue the name deque stands for "double-ended queue The difference between the two is that with a deque, you can insert, remove, or view, from either end of the structure. Attached to this assignment are the two source files to get you started: Dequejava the Deque interface; the specification you must implement Base Dequejava The driver for Deque testing; includes some simple testing code. Your first step should be to review these files and satisfy yourself that you understand the specification for a Deque Your goal is implement this interface, in addition to doing a write Implementing this ADT will involve creating 9 methods: public Last NameDeque() a constructor 4 points] public void enqueue Front (Item element) see interface 16 points] public void enqueueBack(Item element) see interface 16 pointsl For this assignment, you will practice writing a deque ADT (i.e., LastnameDeque). A deque is closely related to a queue the name deque stands for "double-ended queue The difference between the two is that with a deque, you can insert, remove, or view, from either end of the structure. Attached to this assignment are the two source files to get you started: Dequejava the Deque interface; the specification you must implement Base Dequejava The driver for Deque testing; includes some simple testing code. Your first step should be to review these files and satisfy yourself that you understand the specification for a Deque Your goal is implement this interface, in addition to doing a write Implementing this ADT will involve creating 9 methods: public Last NameDeque() a constructor 4 points] public void enqueue Front (Item element) see interface 16 points] public void enqueueBack(Item element) see interface 16 pointsl
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
