考虑以下链接列表:
S是标题指针,P是空指针。在此链接列表中依次执行给定的操作:
(i) P = S → next → next → next
(ii) P → next → next → next → next = S → next → next → next → next
(iii) S → next → next → next = P → next → next
(iv) X = S → next → next → next → next → next → next → next → data
X的值是多少?
(A) 5
(B) 6
(C) 7
(D)分割错误答案: (C)
说明:按顺序执行给定操作后,最终链表将如下所示:
(i) P = S → next → next → next
P = 1000 → 2000 → 3000 → 4000
(ii) P → next → next → next → next = S → next → next → next → next
P → 5000 → 6000 → 7000 → null = S → 2000 → 3000 → 4000 → 5000
(iii) S → next → next → next = P → next → next
S → 2000 → 3000 → 4000 = P → 5000 → 6000
因此,X的值为:
X = S → next → next → next → next → next → next → next → data
X = 1000→2000→3000→6000→7000→5000→6000→7000→7
X = 7
因此,选项(C)是正确的。
这个问题的测验