Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

public class SortedLinkedList { /** * The 0th indexed Node in the list, the nth indexed Node in the list. */ Node head, tail; /**

image text in transcribedimage text in transcribedimage text in transcribed

public class SortedLinkedList {

/** * The 0th indexed Node in the list, the nth indexed Node in the list. */ Node head, tail;

/** * Creates a SortedLinkedList. */ public SortedLinkedList() { head = null; tail = null; }

/** * Inserts the given data at a location that maintains sorted order (ascending). * @param data The value to be inserted into the list. */ public void insertSorted(int data) { }

/** * Deletes the Node at the given index. * @param data Index of the int to be deleted. * @return If the data was deleted. */ public boolean delete(int data) { return false; }

/** * Gets the int at the given index. Throws an IndexOutOfBoundException if index * is negative or too large. * @param idx Index of the int to be return. * @return The int at the given index */ public int get(int idx) { throw new IndexOutOfBoundsException(); }

/** * Searches for the given int and returns its index if found. If the int is not * found, returns -1. * @param data The int to search for. * @return The data at the given index */ public int search(int data) { return -1; }

@Override public String toString() { return printList(); }

/** * A recursive helper for toString that generates a String representation of this. * @return A String representation of the this. */ private String printList() { String listStr = ""; String delimiter = ", "; Node cur = head; while (cur != null) { listStr += cur.data + delimiter; cur = cur.next; }

return listStr.substring(0, listStr.length()-delimiter.length()); } }

The following is already provided to you: Node.java: public class Node \{ int data; Node next; public Node ( int data, Node next) \& this.data = data; this.next = next; \} public class SortedLinkedList \{ Node head, tail; public SortedLinkedList() head = null; t tail = null; \} InsertSorted: Should take in the value to be inserted. It so that the list remains sorted. For instance, if the list is t list={3,5,11} And insertSorted(7) is called, it should insert 7 after 5 an the following list: list={3,5,7,11} Delete: Should take in the value that is to be deleted. It should delete the given value and return true if there is a deletion. If the item was not found, it should return false. Get: Should take in an index. If the index is negative, or equal or out of bounds, it should generate an IndexOutOfBoundsException Otherwise, it should return the item at the provided index. Search: Should take in a value to search for and return the index of this item. If the item is not found, it should return 1. Test Cases Using Junit, please provide test cases that test the accuracy of your methods. You should test insertSorted, delete, get, and search. Remember, your tests should have 100% code coverage. - SortedLinkedList.java - SortedLinkedListTest.java

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions