Please explain why each statement is either right or wrong, thanks! :-) Which of
ID: 3886634 • Letter: P
Question
Please explain why each statement is either right or wrong, thanks! :-)
Which of the given solutions is the correct output after executing the fun method on the linked list defined below. Note, we pass the first element 'f' of linked list defined below as a parameter to fun. Client code: var input = f - > r - > e - > d - > i - > v - > i - > d - > e - > r - > null: public Node fun(Node x) { Node first = x: Node magic = null: while (first != null) { Node second = first.next: first.next = magic: magic = first: first = second: } return magic: } f - > d - > r - > v - > r - > d - > null f - > v - > i - > r - > e - > d - > null d - > e - > r - > i - > v - > i - > r - > e - > d- > f - > null r - > e - > d - > i - > v - > i - > d - > e - > r - > f - > nullExplanation / Answer
corect ans is option d
r- e- d- i- v- i- d- e- r- f- null
since the code is reversing the linked list
since when the function is called
first = f
magic = null
then
second = first.next = r
first.next = magic = null
magic = first =r
first = second = r
and so on