Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Help complete all function in the MyDequeEmpty.java, and use A2DequeDriver.java to test it, thank you ! all subject needed to be completed is noted with

Help complete all function in the MyDequeEmpty.java, and use A2DequeDriver.java to test it, thank you !

all subject needed to be completed is noted with to be completed.

A2DequeDriver.Java

public class A2DequeDriver

{

public static void main(String[] args)

{

System.out.println(" Entering MyDeque testing...");

DequeTest();

System.out.println("MyDeque testing complete!");

}

public static void DequeTest()

{

MyDeque deqA = new MyDeque();

if (deqA.isEmpty()){

System.out.println("deque is empty");

try{

System.out.println(deqA.pollLast() + " " + deqA.size());}

catch (Exception e){

System.out.println(e.getMessage() + " " + deqA.size());}

}

else

System.out.println("deque is not empty");

deqA.offerLast("My");

deqA.offerLast("younger");

deqA.offerLast("brother");

deqA.offerLast("in");

deqA.offerLast("Sweden");

if (deqA.isEmpty())

System.out.println("deque is empty");

else

System.out.println("deque is not empty");

System.out.println(deqA.pollFirst() + " " + deqA.size());

System.out.println(deqA.pollFirst() + " " + deqA.size());

System.out.println(deqA.pollFirst() + " " + deqA.size());

System.out.println(deqA.pollFirst() + " " + deqA.size());

System.out.println(deqA.peekFirst()+ " " + deqA.size());

MyDeque deqB = new MyDeque();

if (deqB.isEmpty()){

System.out.println("deque is empty");

try{

System.out.println(deqB.pollFirst() + " " + deqB.size());}

catch (Exception e){

System.out.println(e.getMessage() + " " + deqB.size());}

}

else

System.out.println("deque is not empty");

deqB.offerFirst("My");

deqB.offerFirst("younger");

deqB.offerFirst("brother");

deqB.offerFirst("in");

deqB.offerFirst("Sweden");

if (deqB.isEmpty())

System.out.println("deque is empty");

else

System.out.println("deque is not empty");

System.out.println(deqB.pollFirst() + " " + deqB.size());

System.out.println(deqB.pollFirst() + " " + deqB.size());

System.out.println(deqB.pollFirst() + " " + deqB.size());

System.out.println(deqB.pollFirst() + " " + deqB.size());

System.out.println(deqB.peekFirst()+ " " + deqB.size());

}

}

MyDequeEmpty.java

public class MyDeque

{

private class DListNode

{

public IT data;

public DListNode prev;

public DListNode next;

public DListNode(IT value)

{

data = value;

prev = null; //reference to the previous node

next = null; //reference to the next node

}

}

// private members (attributes)

private DListNode first, last;

private int size;

// default constructor

public MyDeque(){

// to be completed

}

// insert an item at the front of the deque

public void offerFirst(T item){

// to be completed

}

// insert an item at the end of the deque

public void offerLast(T item){

// to be completed

}

// Remove and return an item from the front of the deque

// Throws an IllegalStateException if the deque is empty

public T pollFirst(){

// to be completed

}

// Remove and return an item from the end of the deque

// Throws an IllegalStateException if the deque is empty

public T pollLast(){

// to be completed

}

// Return the item at the front of the deque. Does not remove item

// Throws an IllegalStateException if the deque is empty

public T peekFirst(){

// to be completed

}

// Return the item at the end of the deque. Does not remove item

// Throws an IllegalStateException if the deque is empty

public T peekLast(){

// to be completed

}

// Returns the number of items in the queue

public int size()

{

// to be completed

}

// Returns whether the queue is empty

public boolean isEmpty()

{

// to be completed

}

}

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

Pro Oracle Fusion Applications Installation And Administration

Authors: Tushar Thakker

1st Edition

1484209834, 9781484209837

More Books

Students also viewed these Databases questions

Question

in c programming this should be the output:

Answered: 1 week ago