考虑以下链表:
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 的值是多少?
(一) 5
(乙) 6
(三) 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)是正确的。
这个问题的测验