我很困惑,爲什麼最後的答案(選擇如)在這個選擇題錯誤:迭代器如何工作? (可多選)
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