Zookal
Zookal

We’d love to hear any feedback or comment from you!

© 2011-2021 Zookal Pty Ltd

View question and answer

From our collection of questions and answers
Engineering · Computer Science
Question details

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<T> that has the following attributes:

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!

Answer
Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.

Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.