Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please create a Node class for a singly-linked list that uses a String as its data. Next, write a linked list class that allows us
Please create a Node class for a singly-linked list that uses a String as its data.
Next, write a linked list class that allows us to store strings in a sorted order. The class should have the following methods:
- add - adds the passed-in String to the list so that the list is always sorted alphabetically (you can use the compareTo method from the string class to assist in the sort.
- remove - removes the first node containing the passed in string. Returns true if the remove was successful, or false otherwise
- toString - returns a string containing the contents of the list separate by commas
- indexOf - returns the position of the node that contains the passed-in string. If no node is located, returns Integer.MIN_VALUE
- removeNodeAt - removes the node at the specified index if possible. Return the removed string if the remove worked, or an empty string if it did not.
- Write a main method.
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