Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!