java program : Given the following method to be considered within the SingleLinkedList class, what does this method do? public void Undefined() { Node ptr = head; if (ptr == null || ptr.next == null) return false; E item1 = ptr.data; while (ptr.next != null) ptr = ptr.next; E item2 = ptr.data; if (item1.equals(item2)) { head = head.next; size--; } }
java program :
Given the following method to be considered within the SingleLinkedList class, what does this method do?
public void Undefined()
{
Node<E> ptr = head;
if (ptr == null || ptr.next == null) return false;
E item1 = ptr.data;
while (ptr.next != null)
ptr = ptr.next;
E item2 = ptr.data;
if (item1.equals(item2))
{
head = head.next;
size--;
}
}
-
If the first element of the list is equal to the second element of the list, then the method deletes the second node.
-
If the first element of the list is equal to the last element of the list, then the method deletes the first node.
-
If the first element of the list is equal to the second element of the list, then the method deletes the first node.
-
If the first element of the list is equal to the last element of the list, then the method deletes the last node.
Step by step
Solved in 2 steps