Need help with Java programming please. Thank you Extend the class Linked List C
ID: 3828049 • Letter: N
Question
Need help with Java programming please. Thank you
Extend the class Linked List Class by adding the following operations: Find and delete the node with the smallest info in the list. (Delete only the first occurrence. Traverse the list only once.) Call the method implementing this operation delete Smallest and include it as an abstract method in the class Linked List class. Write the definition of this method for the class Unordered Linked List. Also, write a program to test your method. Find and delete all the occurrences of a given info from the list. (Traverse the list only once.) Call the method implementing this operation delete All and include it as an abstract method in the class Linked List Class. Write the definition of this method for the class Unordered Linked List. Also, write a program to test your method.Explanation / Answer
public class UnorderedLinkedListClass<T> extends LinkedListClass<T> {
Node runner; // A node for traversing the list.
Node previous; // Always points to the node preceding runner.
runner = this.head.next; // Start by looking at the SECOND list node.
previous = this.head;
public void deletesmallest(T info)
{
while ( runner != null ) {
// Go through the list looking at the objecct in each
// node. If the string is the one we are looking for,
// return true, since the string has been found in the list.
if ( runner.item.equals(info) )
{
previous.next=runner.next;
//delete just the first occurence and retrun;
return;
}
}
runner = runner.next;
}
public void deleteAll(T info)
{
while ( runner != null ) {
// Go through the list looking at the objecct in each
// node. If the string is the one we are looking for,
// return true, since the string has been found in the list.
if ( runner.item.equals(info) )
{
previous.next=runner.next;
//delete just the first occurence and retrun;
return;
}
}
runner = runner.next;
}
}