samedi 2 juillet 2016

preorder and post-order traversal in c++ stl set and map

I have read set and maps provided in c++ STL are implemented using tree, so can i traverse them as tree ? can i get pre-order and post-order traversal of a set or map? i know i can get in-order traversal by simply iterating over all the elements.

set<int> tree;
tree.insert(1);
tree.insert(2);
tree.insert(3);

inorder traveral for this tree should be 1,2,3 and preorder 2,1,3 and post-order 1,3,2. How can i get letter two if i have tree as set?

Thanks!!

Aucun commentaire:

Enregistrer un commentaire