Each node of a singly linked list has fields v and next. The function below reverses the list whose head is h, and returns the new head.
def rev(h):
p = None
while h:
STATEMENT
return p
Python evaluates the whole right-hand side of a multiple assignment first and then assigns the targets from left to right. Which of the following, used as STATEMENT, make rev correct for every list?
- Ah.next, p, h = p, h, h.next
- Bp, h.next, h = h, p, h.next
- Ch, h.next, p = h.next, p, h
- Dnxt = h.next; h.next = p; p = h; h = nxt