Name: Anonymous 2008-05-18 15:57
This is supposed to find the mode of a partially filled array. it does not work yet is tis code my CS teacher gave me. what the fuck is wrong with it?
int findMode(int array[], int size)
{
int occ = 0, result, index = 0, mode = 0;
for( ; index < size; index += result)
{
result = linSearch(array, size, array[index]);
if(result < occ)
{
mode = array[index];
occ = result;
}
}
return mode;
}
//////////
int linSearch(int array[], int size, int target)
{
int i;
for(i = 0; i < size; i++)
if(array[i] == target)
return i;
return -1;
}
int findMode(int array[], int size)
{
int occ = 0, result, index = 0, mode = 0;
for( ; index < size; index += result)
{
result = linSearch(array, size, array[index]);
if(result < occ)
{
mode = array[index];
occ = result;
}
}
return mode;
}
//////////
int linSearch(int array[], int size, int target)
{
int i;
for(i = 0; i < size; i++)
if(array[i] == target)
return i;
return -1;
}