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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:41:25+00:00 2026-05-30T05:41:25+00:00

So I’ve been at this mode thing for a while, and got some help

  • 0

So I’ve been at this mode thing for a while, and got some help figuring out just how to do it on here and thought I might ask for a little more assitance. I’ve got this much figured out.

map<int,unsigned> frequencyCount;
//This is my attempt to increment the values of the map everytime one of the same numebers 
for(size_t i = 0; i < v.size(); ++i)
    frequencyCount[v[i]]++;

unsigned currentMax = 0;
unsigned checked = 0;
unsigned mode = 0;
for(auto it = frequencyCount.cbegin();
    it != frequencyCount.cend(); ++it )

if (it ->second > currentMax)
    {
        mode = it->first;
        currentMax = it->second;
    }

if (currentMax == 1)
{
    cout << "There is no mode in the vector" << endl;
}

else {
cout << " The mode of the vector is: " << mode << endl;
}

}

So it will reutrn the most frequently occuring int within the vector, and return that there is no mode if the none of the map values exceed 1. Now I’ve been trying to figure out what to in the case of more than one mode, ex. 1 2 3 3 4 4 5 currently returns 3. I would like to reutrn 3 and 4.

Logically I would say an if statement checking the variable which occurs most frequently against the second most frequent would work. Of course there is the possibility of 400 modes if the test data is large enough though. So I would need to create a loop the goes through checking and exits when the current variable is no longer equal to the one that occurs one less frequently than it. I’m just really not sure how to go about that. Any advice on where to get started?

  • 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-30T05:41:26+00:00Added an answer on May 30, 2026 at 5:41 am

    As you point out, the mode is not necessarily unique.

    So, you should supply the answer as a set of numbers, as you’ve correctly stated.

    I would create a vector to store the set of unique modes from your set, then output the content of the mode vector.

    e.g.

    std::vector<float> Modes;
    
    // 3 is detected as mode as it occurs 3 times in your set
    Modes.push_back(3);
    
    // 4 is also detected as mode, since it also occurs 3 times in your set
    Modes.push_back(4);
    
    // output the modes for the set
    std::cout << "the following mode(s) were detected in the set";
    for( int n = 0; n < Modes.size(); n ++ )
    {
      std::cout << "Mode: " << Modes[n] << "\n";
    }
    

    hope this makes sense

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have some data like this: 1 2 3 4 5 9 2 6
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
i got an object with contents of html markup in it, for example: string
Specifically, suppose I start with the string string =hello \'i am \' me And

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.