Question: Hi need help with this method, as it needs to sort in alphabetical order. public void addElement(Object element) The addElement adds the parameter element into
Hi need help with this method, as it needs to sort in alphabetical order.
public void addElement(Object element)
The addElement adds the parameter element into the linked list. The linked list should contain all elements (strings) in alphabetical order. Therefore, in this addElement method, a correct location to insert the parameter element needs to be searched and the element needs to be inserted in that location.
It needs to be integrated with an interface. ListIterator.java .
// ListIterator.java
// The ListIterator interface allows access of a position in a linked list. // This interface contains a subset of the methods of the // standard java.util.ListIterator interface. The methods for // backward traversal are not included. public interface ListIterator { //Move Moves the iterator past the next element. Object next(); // Tests if there is an element after the iterator position. boolean hasNext(); // Adds an element before the iterator position // and moves the iterator past the inserted element. void add(Object element); // Removes the last traversed element. This method may // only be called after a call to the next() method. void remove(); // Sets the last traversed element to a different value. void set(Object element); }
Thanks in advnace
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
