The next questions refer to the following linked list node class public class Li
ID: 3671327 • Letter: T
Question
The next questions refer to the following linked list node class public class ListNode private object data private ListNode next: public Listhode (Object initialData, ListNode initialNext) setData (initialData) setNext (initialNext) public object getData) public ListNode getNextO public final void setData (object newData) i return data: return nexti data newData: public final void setNext (ListNode newNext)t next newNext: 4. (5 points) If head refers to the first node of a linked list with two nodes, as follows: ListNode head new ListNode (new Integer (1), new ListNode (new Integer (2), null)): ( ie: head ->1 -2) ie: head->1 2) Which of the following statements would change the list to the following? head -> 3->1 2 A. head. setNext (new ListNode (new Integer (3), head.gethext 0)) B. head. sethext (new List Node (new Integer (3), head)): C. head - new ListNode (new Integer (3), head): D. head new ListNode (new Integer (3))Explanation / Answer
Solution 1:
head = new ListNode(new Integer(3), head);
Solution 2:
head -> B -> C -> D -> E
because:
head= mince(head);
mince(head)
{
r=null;
p=null;
r= head.getNext(); // r=A
head.setNext(p); //next=p;
p= head; // p= B -> C-> D-> E
head = r;
return p; // retrurn head -> B -> C -> D -> E
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.