Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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> { //Implements a generic singly linked list of Comparable objects //Sorted in descending order private class Node { private T data; private Node next; private Node(T d, Node n) { data = d; next = n; } }

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 s1, SortedList s2) { //PRE: s1.size() > 0 && s2.size() > 0 // Constructor for the list created from two SortedLists //A new SortedList is created containing all the data from s1 and s2 //The implementation must take advantage of the fact that s1 and s2 //are sorted. The implementation cannot use the insert method }

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

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David J. Auer

3rd Edition

0131986252, 978-0131986251

More Books

Students also viewed these Databases questions

Question

help asp

Answered: 1 week ago