Check to see if an element exists in a 2D array C++ -


i trying check see if character element in output array. array getting frequency of characters in string. want if current character in array add 1 frequency else add character array frequency of 1. also, want table display top 5 highest frequency's in order.

ex of table should like:

  character: b c d   freqency:  1 2 3 4   string input = getinputstring(inputfilename); char ** output;   (int = 0; < sizeof(output); i++) {       if (input [count] == output[i][]) // issue       {              //.......       }  } 

you use std::vector<std::pair<char,int>> store character , it's count.

string input("1212345678999");  std::vector<std::pair<char, int>> sp; for(auto c : input) {   auto = std::find_if(sp.begin(), sp.end(),                           [=](const pair<int, char>& p) {return p.first == c; });   if (it != sp.end())   {     it->second++;  // if char found, increase count   }   else   {     sp.push_back(std::make_pair(c, 1)); // new char, add entry , initialize count 1   } } 

to display top 5 highest frequency's in order, sort count in decent order:

std::sort(sp.begin(), sp.end(),                        [](const pair<int, char>& p1, const pair<int, char>& p2)                       {                          return p1.second > p2.second;                        }); 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -