Which of the following code snippets would properly complete method insert , whi
ID: 3915423 • Letter: W
Question
Which of the following code snippets would properly complete method insert, which should add the supplied Student object to the front of the list.
first = s;
s.setNext (first);
s.setNext (first);
first = s;
s.setNext (last);
first = s;
first = s;
s.setNext (first);
public class Student f private Student next private String name, id: public Student (String n, String ) name = n; idi next = null; public void setNext (Student s) t next S: public Student getNext( f return next: public class LinkList private Student first; public LinkList O first = null; public boolean isEmpty) //returns true if the list is empty, false if it has at least one element public void push (Student s)t //inserts the element in the front of the listExplanation / Answer
Answer is option B. s.setNext(first), first=s.
As we have first as our head node which is first node of the link list.Now,Student s will have to point to first node to get attached to the link list.So, next node of object s will point to first.And to make object s as head node we have to make first node point to object s.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.