Question: Hello, I am taking a Data Structures and Algorithms class in Java this semester. We were just introduced to Stacks and Queues and in one
Hello,
I am taking a Data Structures and Algorithms class in Java this semester. We were just introduced to Stacks and Queues and in one part of the assignment we are asked to create a Deque which I do not really know how to implement. I have attached the description of the problem and notes from the instructor.
Thanks!
Assignment:

Notes from Professor:
Your class Deque in Assignment 2 should look like this:
class Deque
{
private int maxSize;
private long[] dekArray;
private int left;
private int right;
private int nItems;
//--------------------------------------------------------------
public Deque(int s) // constructor
{
maxSize = s;
dekArray = new long[maxSize];
int center = maxSize/2 - 1;
left = center+1; // left and right
right = center; // start out "crossed"
nItems = 0;
}
// other methods
}
How to test class Deque?
You do not need to define a print method to test Deque. Just use insert and remove methods themselves.
For example,
when you call insertLeft three times on 1, 2, 3; then call removeLeft three times, you should get 3, 2,1.
when you call insertLeft three times on 1, 2, 3; then call removeRight three times, you should get 1, 2, 3.
Similar to insertRight method.
1. Create a Deque class based on the discussion of deques (double-ended queues). It should include insertLeft ),insertRight(), removeLeft ), removeRight), peekRight, peekLeft , isEmpty),and isFull () methods. It will need to support wraparound at the end of the array, as queues do. Write a driver class DequeApp to test class Deque
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
