Answered step by step
Verified Expert Solution
Question
1 Approved Answer
using this--> /** * Node class used for implementing your LinkedDeque. * * DO NOT MODIFY THIS FILE!! * */ public class LinkedNode { private
using this--> /** * Node class used for implementing your LinkedDeque. * * DO NOT MODIFY THIS FILE!! * */ public class LinkedNode{ private T data; private LinkedNode previous; private LinkedNode next; /** * Creates a new LinkedNode with the given T object and node references. * * @param previous the previous node in the list * @param data the data stored in the new node * @param next the next node in the list */ public LinkedNode(LinkedNode previous, T data, LinkedNode next) { this.previous = previous; this.data = data; this.next = next; } /** * Creates a new LinkedNode with only the given T object. * * @param data the data stored in the new node */ public LinkedNode(T data) { this(null, data, null); } /** * Gets the data stored in the node. * * @return the data in this node */ public T getData() { return data; } /** * Gets the next node. * * @return the next node */ public LinkedNode getNext() { return next; } /** * Sets the next node. * * @param next the new next node */ public void setNext(LinkedNode next) { this.next = next; } /** * Gets the previous node. * * @return the previous node */ public LinkedNode getPrevious() { return previous; } /** * Sets the previous node. * * @param previous the new previous node */ public void setPrevious(LinkedNode previous) { this.previous = previous; } @Override public String toString() { return "Node containing: " + data; } }
please complete this:=========================================================================
public class LinkedDeque{ // Do not add new instance variables and do not add a new constructor. private LinkedNode head; private LinkedNode tail; private int size; /** * Adds the data to the front of the deque. * * This method must run in O(1) time. * * @param data the data to add to the deque * @throws java.lang.IllegalArgumentException if data is null */ public void addFirst(T data) { } /** * Adds the data to the back of the deque. * * This method must run in O(1) time. * * @param data the data to add to the deque * @throws java.lang.IllegalArgumentException if data is null */ public void addLast(T data) { } /** * Removes the data at the front of the deque. * * This method must run in O(1) time. * * @return the data formerly at the front of the deque * @throws java.util.NoSuchElementException if the deque is empty */ public T removeFirst() { } /** * Removes the data at the back of the deque. * * This method must run in O(1) time. * * @return the data formerly at the back of the deque * @throws java.util.NoSuchElementException if the deque is empty */ public T removeLast() { } /** * Returns the number of elements in the deque. * * Runs in O(1) for all cases. * * DO NOT USE THIS METHOD IN YOUR CODE. * * @return the size of the list */ public int size() { // DO NOT MODIFY! return size; } /** * Returns the head node of the linked deque. * Normally, you would not do this, but it's necessary for testing purposes. * * DO NOT USE THIS METHOD IN YOUR CODE. * * @return node at the head of the linked deque */ public LinkedNode getHead() { // DO NOT MODIFY! return head; } /** * Returns the tail node of the linked deque. * Normally, you would not do this, but it's necessary for testing purposes. * * DO NOT USE THIS METHOD IN YOUR CODE. * * @return node at the tail of the linked deque */ public LinkedNode getTail() { // DO NOT MODIFY! return tail; } }
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