T********3 发帖数: 19 | 1 where F is a pointer to the first element in the list and L is a pointer to
the last element
en the list. The time of which of the following operations depends on the
length of the
list?
(A) Delete the last element of the list.
(B) Delete de first element of the list.
(C) Add an element after the last element of the list.
(D) Add an element before the first element of the list.
(E) Intechange the first two elementsof the list.
为啥正确答案是C啊? | C********e 发帖数: 492 | 2 答案错了把
liveramp online面试? | f***c 发帖数: 338 | 3 http://www.cs.sfu.ca/~yonas/personal/Downloads/CS_GRE.pdf
Remember that after performing any operation, the structure of the list must
remain
intact; in other words F and L must point to the ¯rst and last elements
respectively.
Choice B needs only the operation F = F->next;
Choice C needs only the operations L->next = new node, L = new node;
Choice D needs only the operations new node->next = F, F = new node;
Choice E needs only the operations T=F, F=F->next, T->next=F->next, F->next=
T;
All these do not depend on the length of the list. The answer is therefore A
. Indeed
in order to delete the last element from the list, we need to ¯rst
locate the element
before the last (which can not be accessed from L). Thus we must parse all
the list
from the ¯rst till the element just before the last after which we can
delete the last
element and assign L to the one before. | h***k 发帖数: 161 | |
|