Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我已经阅读了 C++ STL 中提供的集合和映射是使用树实现的,所以我可以将它们作为树遍历吗?我可以获得集合或地图的预购和后购遍历吗?我知道我可以通过简单地遍历所有元素来进行有序遍历。
set<int> tree; tree.insert(1); tree.insert(2); tree.insert(3);
这棵树的中序遍历应该是 1,2,3 和前序 2,1,3 和后序 1,3,2。如果我有树,我怎么能得到字母二?
谢谢!!
Stl set 和 map 是平衡树(如红黑树)。他们不只是插入元素并将其保持在一个顺序,他们可以平衡他们的元素以保持树 h O(logn)。所以你的元素不一定在你想象的树中,并且没有函数可以让你看到它们是如何的。