Hi there,
I need to write a java code to find the mode of a set of numbers (number i.e., repeated most number of times in a array). Any ideas/help is appreciated......
Thanks in advance....
Printable View
Hi there,
I need to write a java code to find the mode of a set of numbers (number i.e., repeated most number of times in a array). Any ideas/help is appreciated......
Thanks in advance....
Return sourceIndex if you want to know where the first occurrence of the element is, or sourceElement if you want to know the "value" of the elementCode:sort the array
int max = 0;
int count = 0;
int sourceIndex = 0;
int maxIndex = 0;
int currentIndex = 0;
Type maxElement = null;
for( ; currentIndex < arraylength; ++currentIndex )
sourceIndex = currentIndex;
sourceElement = array[currentIndex];
while array[currentIndex] equals sourceElement
count++;
currentIndex++;
if count is larger than max
max = count;
maxIndex = sourceIndex;
maxElement = sourceElement;
count = 0;
return sourceIndex