Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Finding the mode in an array...

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;
}

Name: Anonymous 2008-05-18 16:31

USE CODE TAGS FOR FUCK'S SAKE. USE FUCKING CODE TAGS.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List