Question: Consider the following linked list representation: head [ 1 2 ] [ 4 5 ] [ 7 8 ] [ 3 4 ] [ null

Consider the following linked list representation: head [12][45][78][34][null]
Which of the following code snippets will set the node containing 78 as the last node of your list?
1) Node current = head; while (current.getNext()!= null){ current = current.getNext(); } current.setNext(null);
2) Node current = head; while (current.getNext()!= null){ current = current.getNext(); } current.setNext(null); current.setInfo(78);
3) Node current = head; while (current.getNext()!= null && current.getInfo()!=78){ current = current.getNext(); } current.setNext(null);
4) Node current = head; current.setNext(current.getNext().getNext());

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