Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help with this java program. For this assignment, you will practice writing a deque ADT (i.e., LastnameDeque). A deque is closely related to a

Please help with this java program.

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 di erence 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 les to get you started:

Deque.java - the Deque interface; the speci cation you must implement.

BaseDeque.java - The driver for Deque testing; includes some simple testing code.

Your rst step should be to review these les and satisfy yourself that you understand the speci cation for a Deque.Your goal is implement this interface, in addition to doing a write. Implementing this ADT will involve creating 9 methods:

public LastNameDeque() - a constructor [4 points] public void enqueueFront(Item element) - see interface [6 points] public void enqueueBack(Item element) - see interface [6 points]

1

public Item dequeueFront() - see interface [5 points] public Item dequeueBack() - see interface [5 points] public Item rst() - see interface [2 points] public Item last() - see interface [2 points]

public boolean contains() - see interface [2 points] public boolean isEmpty() - see interface [2 points] public int size() - see interface [2 points] public String toString() - see interface [4 points]

Lastly, write appropriate testing documentation - see next section. [10 points] From Section 1, be sure that you:

Make all operations (except toString) work in O(1). Do not import any packages other than java.util.NoSuchElementException. Use a doubly linked list data structure. Hint: you may need to create a node class.

Deque Class is given below

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 a given element exists inside the deque, false * otherwise. * @return if element exists in list */ public boolean contains(Item element); /** * 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(); }

The base Deque is given below.

/** * 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()); } } 

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

Students also viewed these Databases questions

Question

How to use this book

Answered: 1 week ago