We recently discussed deques, which are Double-Sided Queues. For this part, you will implement a deque. You will call this class Deque, which will be stored in a Deque.java file.

The requirements for the deque are as follows.

Your deque should accept integers.

You should be able to:

  • add and remove to the end of the queue.
  • add and remove from the front of the queue.
  • check if the deque is empty.
  • peek at the end's value.
  • peek at the front's value.

The following restrictions should also be followed:

  • You are not allowed to implement the deque using an ArrayList. You must implement the deque with an array.
  • Your array will take up to a max of 10 variables.
  • If your deque is full, you shouldn't be able to add new elements to the array.

Your Main.java file will contain a single main function. Your program should loop indefinitely unless the user enters the word "exit".

In your loop, give the user the option to choose an action for how they'll interact with the deque. Options include:

  • adding to the front
  • adding to the rear
  • removing from the front
  • removing from the rear
  • peeking at the the front value
  • peeking at he end value

If the user asks to add a value to the queue, give them the option to choose an integer to add. When they press enter, the value they entered should be added to the deque. You should then print out the contents of the deque.

If the user asks to remove a value, the appropriate value should be removed.

If the user asks to peek at the front or rear, the appropriate value should be printed to the screen. The loop should repeat until "exit" is typed in. (Or you can give the user a yes/no option to continue. In essence, the user should be able to type something in to exit the loop.)

Sample Runs

Type in deque option (options: addFront, addRear, removeFront, removeRear, peekFront, peekRear): addRear
Enter a value to store in deque (type 'exit' to quit): 5
Deque: [5]

Type in deque option (options: addFront, addRear, removeFront, removeRear, peekFront, peekRear): addRear
Enter a value to store in deque (type 'exit' to quit): 10
Deque: [5, 10]

Type in deque option (options: addFront, addRear, removeFront, removeRear, peekFront, peekRear): addFront
Enter a value to store in deque (type 'exit' to quit): 152
Deque: [152, 5, 10]

Type in deque option (options: addFront, addRear, removeFront, removeRear, peekFront, peekRear): peekFront
Front value: 152
Deque: [152, 5, 10]

Type in deque option (options: addFront, addRear, removeFront, removeRear, peekFront, peekRear): removeRear
Deque: [152, 5]

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.