Java Using Java Implement a referenced based Deque. Create an inner (inside the
ID: 3911859 • Letter: J
Question
Java
Using Java Implement a referenced based Deque. Create an inner (inside the Deque class) class Node. The Node class will have the attributes:
• T item
• Node next
You will also create a class Deque that has the following attributes:
• Node head
• Node tail
• int items
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.
Explanation / Answer
Hi,
Below is the required class Deque.java with the inner class Node.java and required method. I have also created a main function to test all the methods. Please feel free to test as per your requirements and make changes in main.
Deque.java
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.