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; } /****** 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; }
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 i) 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 correctStep 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