I'm kind of lost. I'm trying to find the mode value in the list. All list are stroed in array. Anyone has any idea?

Well, do you understand what the frequency and mode are? The mode can be easily found once you've obtained the frequency, and the frequency is trivial with the standard library:

#include <cstddef>
#include <iostream>
#include <map>

#define length(x) (sizeof (x) / sizeof *(x))

int main()
{
  int a[] = {1,5,4,5,8,9,5,1,4,7,8,5};
  std::map<int, int> freq;

  for ( size_t i = 0; i < length ( a ); i++ )
    ++freq[a[i]];

  std::map<int, int>::const_iterator it = freq.begin();

  while ( it != freq.end() ) {
    std::cout<< it->first <<": "<< it->second <<std::endl;
    ++it;
  }
}

Now it's just a matter of finding the item with the largest value for second.

thanks to give me an idea. I found out the different way to find the frequency. this is what I did :

int j(1);
mode[j] = slist[1];
freq[j]= 1;

for (int i=2;i<=n;i++)
{
     if (mode[j] == slist[i])
	freq[j]++;
     else
    {
	j++;
	mode [j] = slist [i];
	freq[j]= 1;
    }//end if
	
}//end for

<< moderator edit: added [code][/code] tags >>

well, I found the most frequency and then I found mode!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.