Question: package linked; import java.util.*; /* * This simple doubly linked list class maintains a doubly linked list * with elements in that are in sorted

package linked;
import java.util.*;
/* * This simple doubly linked list class maintains a doubly linked list * with elements in that are in sorted order (smallest to largest) * i.e., the smallest value is in the head node * and the largest value is in the tail node */
public class SortedLinkedList { /* * DO NOT MODIFYY */ static class Node { int data; Node next; Node prev; public Node(int data) { this.data = data; next = null; prev = null; } } Node head; Node tail; /* * DO NOT MODIFY * Returns whether or not a list is empty */ public boolean isEmpty() { return head==null && tail==null; } /* * DO NOT MODIFY * Returns the value in the head node */ public int getHeadData() { return head.data; } /* * DO NOT MODIFY * Returns the value in the tail node */ public int getTailData() { return tail.data; } /* * DO NOT MODIFY * toString method to use for testing */ public String toString() { String s = ""; if(isEmpty()) return s; Node current = head; while(current!=null) { s = s+current.data + ","; current = current.next; } return s.substring(0,s.length()-1); }
/****** THIS IS WHERE YOUR IMPLEMENTATION STARTS******/ /* * Inserts a new node in the linked list with data equal to i * Maintains the sorted order of the list */ public void insert(int i) { } /* * This method returns true if the list is in sorted order */ public boolean isSorted() { return false; } /* * This method returns a Java LinkedList of integers that matches the SortedLinkedList */ public LinkedList
}
Please help me with this code in Java. Thank you.
you will implement some methods on the SortedLinkedList class provided. This class contains a doubly linked list of integers where the integers are stored in ascending order (from smallest to largest). Please do not change any of the method signatures or other code given (including the package name). public void insert (int in) This method inserts a Node containing data equal to i in the sorted linked list and maintains the property that the list is in sorted order from smallest to largest. The example below illustrates how the number 3 would be inserted into the given SortedLinkedList object. public boolean issorted() This method returns true if the SortedLinkedList object is actually sorted in ascending order. You should think about how you could use this method to guarantee that your insert method is correct. public LinkedList getAscending() This method returns a Java LinkedList object where the data in the LinkedList is in the same order as in the SortedLinkedList. For more information on the Java LinkedList class, see the Java documentation linked here. public LinkedList getDescending() This method returns a Java LinkedList object where the data in the LinkedList is in the reverse order as in the SortedLinkedList (i.e, in descending order from largest to smallest). For more
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
