由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 问一个阿三出的面试题: 什么是iterator invalidation?
相关主题
贴一道题,帮忙做做code review (How can we generate all possibilities on braces )Onsite面试题几道
what is the internal implementation of DequeL家和G家的几道面试题不懂
面试题一道count frequency of all words的面试题
雇主不能取消I-140的具体条件是什么?sliding window面试题
问一道C++ template的面试题一道面试题。
问一个linkedin的面试题[合集] 问几道amazon面试题
[google面试题] API流量控制LRU Cache, 请问, 如果我这样写,错误在哪里?为什么会time limit exceeded? 谢谢
问一道A家的面试题面试被三哥黑了,如何去complaint
相关话题的讨论汇总
话题: iterators话题: container话题: references
进入JobHunting版参与讨论
1 (共1页)
t****e
发帖数: 279
1
还有一个是Array和Queue的区别。
还有一个什么是StringBuffer?
最怕回答这类问题,感觉都知道,天天用的东西, 但是却往往回答不好。
s*********e
发帖数: 197
2
Array是顺序存储和随机访问。
Queue是先入先出。
Queue可以用array实现。
s*******u
发帖数: 220
3
http://stackoverflow.com/questions/6438086/iterator-invalidatio

【在 t****e 的大作中提到】
: 还有一个是Array和Queue的区别。
: 还有一个什么是StringBuffer?
: 最怕回答这类问题,感觉都知道,天天用的东西, 但是却往往回答不好。

t****e
发帖数: 279
4
What is iterator invalidation?
Answer:
Insertion
Sequence containers
vector: all iterators and references before the point of insertion are
unaffected, unless the new container size is greater than the previous
capacity (in which case all iterators and references are invalidated) [23.2.
4.3/1]
deque: all iterators and references are invalidated, unless the inserted
member is at an end (front or back) of the deque (in which case all
iterators are invalidated, but references to elements are unaffected) [23.2.
1.3/1]
list: all iterators and references unaffected [23.2.2.3/1]
Associative containers
[multi]{set,map}: all iterators and references unaffected [23.1.2/8]
Container adaptors
stack: inherited from underlying container
queue: inherited from underlying container
priority_queue: inherited from underlying container
Erasure
Sequence containers
vector: every iterator and reference after the point of erase is invalidated
[23.2.4.3/3]
deque: all iterators and references are invalidated, unless the erased
members are at an end (front or back) of the deque (in which case only
iterators and references to the erased members are invalidated) [23.2.1.3/4]
list: only the iterators and references to the erased element is invalidated
[23.2.2.3/3]
Associative containers
[multi]{set,map}: only iterators and references to the erased elements are
invalidated [23.1.2/8]
Container adaptors
stack: inherited from underlying container
queue: inherited from underlying container
priority_queue: inherited from underlying container
Resizing
vector: as per insert/erase [23.2.4.2/6]
deque: as per insert/erase [23.2.1.2/1]
list: as per insert/erase [23.2.2.2/1]
Note 1
Unless otherwise specified (either explicitly or by defining a function in
terms of other functions), invoking a container member function or passing a
container as an argument to a library function shall not invalidate
iterators to, or change the values of, objects within that container. [23.1/
11]
Note 2
It's not clear in C++2003 whether "end" iterators are subject to the above
rules; you should assume, anyway, that they are (as this is the case in
practice).
Note 3
The rules for invalidation of pointers are the sames as the rules for
invalidation of references.
1 (共1页)
进入JobHunting版参与讨论
相关主题
面试被三哥黑了,如何去complaint问一道C++ template的面试题
这道设计面试题这样解对吗问一个linkedin的面试题
[合集] google 面试题[google面试题] API流量控制
贴一道take home的面试题问一道A家的面试题
贴一道题,帮忙做做code review (How can we generate all possibilities on braces )Onsite面试题几道
what is the internal implementation of DequeL家和G家的几道面试题不懂
面试题一道count frequency of all words的面试题
雇主不能取消I-140的具体条件是什么?sliding window面试题
相关话题的讨论汇总
话题: iterators话题: container话题: references