我很困惑,为什么最后的答案(选择如)在这个选择题错误:迭代器如何工作? (可多选)
Which of the following statements is the most accurate regarding linked lists?
a. Linked-lists take up more space than STL vectors because they allocate extra storage
space for future growth.
b. The asymptotic complexity of inserting at the end of a doubly-linked list container
storing only the pointer to the first element is O(1).
c. A loop in a singly-linked-list can be found in O(log(n)) time and O(n) memory overhead
d. A loop in a singly-linked-list can be found in O(n) time and O(1) memory overhead.
e. The number of elements in a linked-list is end_ptr -start_ptr + 1, where start_ptr points
to the first element in the linked list and end_ptr points to the last item of the linked-list.
也就是说,为什么没有都 d。和e。正确?迭代器在什么情况下会返回end_ptr-start_ptr+1
的大小,以及在哪些情况下不会呢?应该选择end_ptr-start_ptr
而不是?
这个问题从哪里来?它是在谈论'std :: list',还是*任何链接列表? – 2013-02-28 02:04:34
因为指向链表中每个元素的指针是相互独立的内存位置,所以如果你认为(e)*是远程*准确的,你可能会考虑一个向量而不是列表。它不应该成为你回答这个问题的候选人名单。 – WhozCraig 2013-02-28 02:06:13
为什么(d)应该是准确的? ISTR你需要O(n^2)时间来做O(1)存储。 – 2013-02-28 02:20:38