def bianli(head):
pt = head
while pt != -1:
print(data[pt][0],data[pt][1],"->",end='')
pt = data[pt][1]
print()
data = [['A',1],['B',2],['C',3],['D',-1]]
head = 0
bianli(head) #遍历链表,显示初始状态为“A 1 ->B 2 ->C 3 ->D -1 ->” qt = head
|
bianli(head) #遍历链表,显示最终状态为“A 2 ->C 1 ->B 3 ->D -1 ->”
执行该程序段后,链表遍历结果由初始状态变为最终状态,上述程序段中方框处可选代码为:
①data[data[qt][1]][1] = pt
②data[qt][1] = data[pt][1]
③data[pt][1] = data[data[pt][1]][1]
则方框处代码的正确顺序是( )