Question: Implement the Deque Abstract Data Type (ADT) described in the text in Section 6.3 Double-Ended Queues. In Java public interface Deque { int size(); boolean

Implement the Deque Abstract Data Type (ADT) described in the text in Section 6.3 Double-Ended Queues.

In Java

public interface Deque {

int size();

boolean isEmpty();

E first();

E last();

void addFirst(E e);

void addLast(E e);

E removeFirst();

E removeLast();

}

The solution must include the following:

The generic Deque interface (Code Fragment 6.14).

Code Fragment 6.14: A Java interface, Deque, describing the double-ended queue ADT. Note the use of the generic parameterized type, E, allowing a deque to contain elements of any specified class.

A static (fixed size, array based) generic implementation of the Deque that implements the Deque interface.

A dynamic (linked based) generic implementation of the Deque that implements the Deque interface.

Add a toString() method and an equals() method to each of your implementations.

Your solutions should be written so that each of the methods (except toString() and equals()) runs in O(1) time.

Test your ADT by creating a Deque of the Player class (from Lab103) and demonstrating that each of your methods works. You may hard code the instances of the Player class into your Client (i.e. you do not have to get input from the keyboard).

public class Player extends Client {

String name; String positionPlayed; int jerseyNumber;

//constructor public Player(String name, String positionPlayed, int jerseyNumber) { this.name = name; this.positionPlayed = positionPlayed; this.jerseyNumber = jerseyNumber; } //Accessor & Mutators

public String getName(String player) { name = player; return name; }

public String getPosition(String position) { positionPlayed = position; return positionPlayed; }

public int getNumber(int number) { jerseyNumber = number; return jerseyNumber; } //to String

public String toString() { String info = "Name: " + name + ", Position: " + positionPlayed + ", Jersey Number: " + jerseyNumber;

return info; } public boolean equals(Player p) { if ( !p.name.equals(name)) return false; if ( !p.positionPlayed.equals(positionPlayed)) return false; if ( p.jerseyNumber != jerseyNumber) return false; return true; }

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!