Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8706077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:31:31+00:00 2026-06-13T03:31:31+00:00

I am using a stl map on gcc comper which uses a tree to

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T03:31:32+00:00Added an answer on June 13, 2026 at 3:31 am

    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::greater as your key instead of std::less.

    e.g.

    std::map< std::string, int, std::greater<std::string> > my_map; 
    

    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

    std::vector<std::string> desiredOrder;
    std::map<std::string, int> myTree;
    
    myTree["A"] = 0;
    desiredOrder.push_back("A"); 
    myTree["B"] = 0;
    desiredOrder.push_back("B");
    myTree["C"] = 0;
    desiredOrder.push_back("C");
    myTree["D"] = 0;
    desiredOrder.push_back("D");
    
    /*
    Do whatever sorting you want to do here....
    */
    
    for (int i = 0; i < desiredOrder.size(); ++i)
    {
        const std::string &s = desiredOrder[i];
        std::cout << s << ' ' << myTree[s] << '\n';
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using stl map to store flow information extracted from pcap files. When
Under the hood, an STL map is a red-black tree, and it uses the
I have an issue with returning an iterator from an STL map using an
I'm new to STL. The thing stumping me about using a map to store
Using GCC 4.x, g++ and STL. Which internal structure should be used to hold
I'm using an STL map with a struct for a key. This is the
Previously, I am using STL map to perform the mentioned task. struct ltstr {
I'm using the STL map data structure, and at the moment my code first
What is the best way to determine if a STL map contains a value
Another small question about STL: i have Dictionary: map <string,vector <Wordy> > Dictionary; using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.