Question: CAN SOMEONE DO THIS SORTED LIST JAVA PROGRAM? WITH GIVEN METHODS? You are to implement a linked list that remains sorted. The linked list should

CAN SOMEONE DO THIS SORTED LIST JAVA PROGRAM? WITH GIVEN METHODS?

You are to implement a linked list that remains sorted. The linked list should be able to store any object as long as the object has implemented the Comparable interface. You may create either a singly linked sorted list or a doubly linked sorted list.

clear- Should reset the list to be empty. Can be called in the default constructor.

getSize- Returns the size of the list.

toString- Returns a string representation of the list.

add- Adds a new object to the list in its sorted position. Starts adding elements in ascending order. If the reverse method has been called, then the order is changed from ascending to descending and vice versa.

If the list is in ascending order then the newData needs to be placed in the list such that node.prev.data newData node.next.data.

If the list is in descending order then the newData needs to be placed in the list such that node.prev.data newData node.next.data.

removeFromIndex- Removes an item from a given position. If the position is out of bounds, then throw an IndexOutOfBoundsException. If the list is empty, then throw a NoSuchElementException. You will need to import this exception.

removeAll- Removes all of a given item. If the list is empty, then throw a NoSuchElementException.

get- Returns the item from a given position. If the position is out of bounds, then throw an IndexOutOfBoundsException.

reverse- Reverses the ordinal direction of the list. If the list is in ascending order, then the list should end up in descending order and vice versa. This will also affect how add behaves.

contains- Takes an element and returns true if the element is in the list and false if it does not.

THANK YOU IN ADVANCE.

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 Databases Questions!