10-08-2009, 00:18
|
|
|
חבר מתאריך: 09.08.09
הודעות: 2
|
|
גם הוא טועה וגם אתה טועה
הוא טועה כי בג'אווה זה תלוי בכמה דברים, לדוגמה בפרמטר capacityIncrement ב-constructor של Vector.
אתה טועה כי ב-CPP התקן לא אומר שום דבר כזה. המימוש של MS מכפיל ב-2 ואולי עוד מימושים עושים את זה, אבל התקן לא מחייב את זה בכלל. הוא אומר דברים כמו:
23.2.4 Template class vector
A vector is a kind of sequence that supports random access iterators. In addition it supports (amortized) constant time insert and erase operation at the end; insert and erase in the middle take linear time. Storage management is handled automatically, though hints can be given to improve efficiency.
23.2.4.3 vector modifiersiterator insert (iterator position , const T& x);
void insert (iterator position, size_type n, const T& x);
template <class InputIterator> void insert (iterator position, InputIterator first, InputIterator last);
...
Complexity: If first and last are forward iterators, bidirectional iterators, or random access iterators, the complexity is linear in the number of elements in the range [first, last) plus the distance to the end of the vector. If they are input iterators, the complexity is proportional to the number of element in the range [first, last) times the distance to the end of the vector.
ועוד ועוד. הסיכום הוא שיש דרישות על סיבוכיות, אבל לא על הקבועים.
|