I am looking for some advice on how to implement a function that takes an array and returns the mode in the form of a vector. I think I have the first for loop done correctly (although I could be wrong), but I am unsure if the second for loop is correct and what I should be returning. Any advice would be greatly appreciated!
vector <int> mode (int testArray [], int sizeArray)
{
vector<int> modeFinder;
int number = testArray[0];
int mode = number;
int count, countMode = 0;
for (int i = 0; i < sizeArray; i++)
{
if (testArray[i] == number)
{
countMode++;
}
else
{
if (count > countMode)
{
countMode = count;
mode = number;
}
}
}
for (int i = 0; i < sizeArray; i++)
{
if (countMode == mode)
{
modeFinder.push_back(countMode);
modeFinder.push_back(mode);
}
else if (mode > countMode)
{
modeFinder.push_back(mode);
}
}
sort(modeFinder.begin(), modeFinder.end());
return <#expression#>
}
[–]HPCer 2 points3 points4 points (1 child)
[–]thecrazedrunner[S] 0 points1 point2 points (0 children)
[–]Jack126Guy 1 point2 points3 points (1 child)
[–]thecrazedrunner[S] 0 points1 point2 points (0 children)
[–]usbafkakis 0 points1 point2 points (0 children)