Create a sortedlist object


Code a doubly linked, sorted list (in ascending order). Each item of the list will just store an int.
You will need to code three classes: Node, SortedList, and GroupProject.
The Node class has three instance variables, all private:

  • an int, representing the value stored inside the Node
  • a Node (next)
  • another Node (previous)

The methods to code are: constructor (at least one), accessors, mutators.
The SortedList class is a doubly linked list, sorted in ascending order.
It has two instance variables, both private:

  • an int, representing the number of items in the list.
  • a Node, representing the head node in the list.

The methods are:

  • insert: this method takes one parameter, an int; it has a void return value.

• delete: this method takes one parameter, an int; it returns a boolean value. If we were successful in deleting the item (i.e., the value of the parameter was found in the list), then we return true; if we were not successful, then we want to output a message that the value was not found, and therefore, not deleted, and returnedfalse.

  • toString: this method takes no parameters and returns a String representation of the list.
  • Constructor (at least one), and accessors and mutators as appropriate.

All methods should keep the list sorted in ascending order.
The GroupProject class contains the main method; it should do the following:

  • create a SortedList object reference
  • insert successively the values 25, 17, 12, 21, 78, and 47 in the sorted list
  • output the contents of the sorted list using the toString method
  • delete from the sorted list the value 30, using the delete method (obviously, 30 will not be found)
  • output the contents of the sorted list using the toString method
  • delete from the sorted list the value 21, using the delete method
  • output the contents of the sorted list using the toString method

Your insert and delete methods should work properly in all possible scenarios: inserting in an empty list, inserting at the beginning of a list, inserting in the middle of a list, inserting at the end of a list, deleting from an empty list (cannot delete), deleting an item not in the list (cannot delete), deleting the first item in a list, deleting in the middle of a list, deleting the last item in a list.

 

Request for Solution File

Ask an Expert for Answer!!
Basic Computer Science: Create a sortedlist object
Reference No:- TGS0763227

Expected delivery within 24 Hours