Question
Hello! I am searching for help with this code. It's for java. I am stuck so help would be greatly appreciated. If you could leave
Hello! I am searching for help with this code. It's for java. I am stuck so help would be greatly appreciated. If you could leave comments in the code so I can get an idea of whats going on would be great. Thank you in advance!
Implement a referenced based Deque. To accomplish this, you will create first create an inner (i.e. inside the Deque class) class Node. The Node class will have the attributes:
T item
Node next
You will also create a class Deque
Node head
Node tail
int nrItems
Also, it will have the following methods:
A constructor that creates an empty deque.
void addFirst(T item) - adds at the head
T removeFirst() - removes from the head
T getFirst() - returns the element at the head
void addLast(T item) - adds at the tail
T removeLast() - removes from the tail
T getLast() - returns the element at the tail
int size() - returns the number of items in the deque
boolean isEmpty() - true if empty false otherwise
String toString() - returns a String representation of the elements in the deque
void clear() - empties the deque.
You will also create a main method that creates an object of the class Deque. You will:
fill it in with 20 random integers between 0 and 100.
Display it.
display a menu to the user with the following options:
add at beginning
add at end
remove from beginning
remove from end
display beginning
display end
display
clear
exit
Be sure to handle the special cases when the Deque has zero or one nodes!
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