Mode Function
-
The function has to find the mode (number most found in the array, for ex. array[]{1, 2, 1, 1} the mode is 1 since it appears 3 times in the array while 2 only apears once. movie is a class and it has a array of ints which movie.return_value(int) accesses. right now the mode equals the first number in the array, its like the second if isant getting evaluated right, anyway in my mind this should work and i cant find a way around it. void getmode(movie_data movie){ int numfound0=0, numfound1=0, mode=0, *num0ptr=&numfound0, *num1ptr=&numfound1, *modeptr=&mode; for(int j=0;j*num1ptr){ num1ptr=num0ptr; *modeptr=movie.return_value(j); } } } cout<<*num1ptr; movie.put_mode(modeptr); cout<
-
The function has to find the mode (number most found in the array, for ex. array[]{1, 2, 1, 1} the mode is 1 since it appears 3 times in the array while 2 only apears once. movie is a class and it has a array of ints which movie.return_value(int) accesses. right now the mode equals the first number in the array, its like the second if isant getting evaluated right, anyway in my mind this should work and i cant find a way around it. void getmode(movie_data movie){ int numfound0=0, numfound1=0, mode=0, *num0ptr=&numfound0, *num1ptr=&numfound1, *modeptr=&mode; for(int j=0;j*num1ptr){ num1ptr=num0ptr; *modeptr=movie.return_value(j); } } } cout<<*num1ptr; movie.put_mode(modeptr); cout<
Hi, Consider this code (yours is not readable):
GetMode(int array[], int count)
{
int freq, max = 0;
for (int i=0; i<count; i++)
{
freq = 0;
for (int j=0; j<count; j++)
{
if (array[j]==array[i])
freq++;
}
if (freq>max)
max = freq;
}
return max;
}You have to replace
array[x]
withmovie.return_value(x)
and maybe some other few things, but the algorythm seems pretty simple. You simply search for the most frequent value in the array. Paolo ------ "airplane is cool, but space shuttle is even better" (J. Kaczorowski)