我用于查找模式(最常见)以及所述模式显示多少次的代码会进入一个永无止境的循环。有谁知道我能做些什么来修复它?
编辑我更新了代码:它返回 0,这不是模式。
void calculateMode(int array[], int size)
{
int counter = 0;
int max = 0;
int mode = 0;
for (int pass = 0; pass < size - 1; pass++)
for (int count = pass + 1; count < size; count++) {
if (array[count] > max) {
max = array[count];
mode = 1;
counter = array[pass];
}
cout << "The mode is: " << counter "It's been displayed: " << count << "times" << endl;
}