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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started