Answered step by step
Verified Expert Solution
Link Copied!

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

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

Recommended Textbook for

Entrepreneurship

Authors: Andrew Zacharakis, William D Bygrave

5th Edition

9781119563099

Students also viewed these Programming questions