Question
Implement the class shown below. The class implements a sorted linked list of Comparable objects. The list is sorted in *descending order*. You must write
Implement the class shown below. The class implements a sorted linked list of Comparable objects. The list is sorted in *descending order*.
You must write a test driver to test your program. Your implementation of the class must not depend on your test driver.
import java.io.*; import java.util.*;
public class SortedList
private Node head; //Reference to the first node in the list private int size; //The number of elements in the list
//When comparing elements in the list use equals or compareTo //do not use == public SortedList() { //Constructor for an empty list head = null; //no sentinel node size = 0; }
public SortedList(SortedList
public void insert(T item) { //If an element in the list matches item do nothing (i.e. the list must not contain // duplicates) otherwise insert item into the list so the list remains sorted
}
public void remove(T item) { //if an element in the list matches item then remove the element for the list //otherwise do nothing
}
public boolean find(T item) { //Return true if the list contains an element that matches item //otherwise return false //Your implementation must be *recursive* n //You can do most of the work in an auxiliary private recursive method
}
public int size() { //Return the number of items in the list
} public String toString() { //Return a string representation of the list //The string representation of the list is a [ followed by the items in the list //separated by commas followed by a ] //For example a list of integers could look like [107,50,10,7,3,2]
}
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