【发布时间】:2011-10-07 00:38:44
【问题描述】:
我想知道在 c++ 的 STL 中设置的迭代器如何工作。我猜这个集合是使用二叉搜索树实现的,这意味着迭代器会按顺序遍历这棵树。但我的问题是,他们什么时候做这个遍历,一开始 当我们喜欢 它= s.begin() 并将遍历的指针存储在内部的某种堆栈中,并在迭代器中的每个增量上仅引用此数据结构 或者迭代器中的增量对树进行新的中序遍历。
我的意思是当我们像这样初始化时
set<int> s;
set<int>::iterator it;
//and then use it like:
for(it = s.begin(); it!=s.end(); )
{
dosth();
++it; // does this do a inorder traversal of the tree again to find the next
// node or it gets the next node in the tree by reading the internal
// data structure(of inorder traversal) which is created when we do s.begin().
}
【问题讨论】:
标签: c++