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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:30:02+00:00 2026-06-04T10:30:02+00:00

Please help me to sort multimap by the count of values. For example, multimap<char,int>

  • 0

Please help me to sort multimap by the count of values.

For example,

multimap<char,int> mymultimap;

mymultimap.insert (pair<char,int>('a',100));
mymultimap.insert (pair<char,int>('a',101));
mymultimap.insert (pair<char,int>('a',111));
mymultimap.insert (pair<char,int>('b',200));
mymultimap.insert (pair<char,int>('b',211));
mymultimap.insert (pair<char,int>('c',300));

Should be after sorting in the following order:

c
b
a

I tried to use custom comparer like this:

struct comparer
{
    bool operator() (const char& first, const char& second) const
    {
        return mymultimap.count(first) < mymultimap.count(second);
    }
};

But I can`t define

multimap<char, int, comparer> mymultimap;

Before the struct comparer was defined.

  • 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-04T10:30:03+00:00Added an answer on June 4, 2026 at 10:30 am

    This is not possible.

    Unless you go ahead and create a custom structure, it would seem that you need one structure to keep trace of all the items (pairs here), and one to actually count them.

    The actual choice mainly depends if the sort operation is a one-off computation or if you actually need to maintain both synchronized.

    If it is a one-off computation, then just count when you need and be done with it.

    If you need to maintain this order, then I would suggest reading on Boost.MultiIndex and using it as a base to develop a custom class.

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

Sidebar

Related Questions

Please help me with the following implementation of Counting Sort in Java. I am
Could please anybody help me to sort it out? It can be done like
Please can someone help sort a noob out? I've posted this problem on various
Please help me to find problem t1=$(sort -k 2,2 f.txt|head -1|cut -d -f3) while
How can we sort an xml file in php without using an xsl?Please help
Please help me to sort my table in MySQL. I need to make it
Please help me: create clickable regions in the canvas below that I can assign
Please help me: I'm getting Error While using j4lOCR: `A fatal error has been
Please help me someone with this code. CSS Code #nav, #nav ul { width:1000px;
Please help me with this issue in my script. At the point of the

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.