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 6985359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:40:12+00:00 2026-05-27T18:40:12+00:00

I want to sort elements in map container using only values not key. how

  • 0

I want to sort elements in map container using only values not key. how to do it? I know that map can sort by key value, but how to do vice versa. I found same question in stackoverfrlow. I like this solution. However I want clarify what does it mean “dump in pair<K,V>“. I don’t want create special structure for that, it is not elegant. how do you implements this solution?

  • 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-05-27T18:40:13+00:00Added an answer on May 27, 2026 at 6:40 pm

    In order to dump the information from a std::map into a std::vector, you can use std::vector’s constructor that takes two iterators.

    std::vector<std::pair<K,V> > myVec(myMap.begin(), myMap.end());
    

    You would then sort it with:

    std::sort(myVec.begin(),myVec.end(),&myFunction);
    

    myFunction would be a function defined with the signature:

    bool myFunction(std::pair<K,V> first, std::pair<K,V> second);
    

    Have it return true if you they are in the right order(i.e. first should be before second). Return false when they are in the wrong order(i.e. second should be before first).


    Also, you might want to look at boost::bimap, which seems more attuned to your problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to sort dictionary based upon value of each dictioanry item.but if i
I have an XML file that contains price value.I want to sort my table
I want to sort on a certain column only for rows containing a certain
I want to sort a flat, associative array by its values alphabetically and preserve
I want to sort array A based on values in Array B actually in
I want to sort a String that has nr. How do I do that?
I want to sort elements of a HashSet<string> and join them by a ;
I want to be able to sort elements based on an attribute in my
I want to sort an XML element by his children elements: <?xml version=1.0 encoding=utf-8?>
if we have n elements with keys:{0,1,-1} and we want to sort them,how many

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.