I am using a stl map on gcc comper which uses a tree to store key,value pairs.
The iterator advances in an inorder fashion so inorder traversal is really easy.
However one of my output requirements is a postorder traversal.
I have been specifically aksed to use map.
Is there any way to get it done?
I am using a stl map on gcc comper which uses a tree to
Share
As Steve Jessop said Map is the abstract data structure provided by c++, you can not change the order of elements stored in map in any order, like we can do in Tree or AVL by traversing in pre/post/in order.
but you can reverse the order of storing by using
std::greateras your key instead ofstd::less.e.g.
OR
crate one Vector desiredOrder, which will keep the trac of order of insertion in map, and once you are done with insertion just do whatever sorting operation you want pre/post/ in order on the desiredOrder Vector and using for loop you can traverse the vector and access the Map elements using the vector value as a key for your Map
e.g