0

What will be the code for finding the element which occurs with maximum frequency and also to display its frequency in an arra.

20th Oct 2016, 8:56 AM
Deepro ghosh
Deepro ghosh - avatar
2 Answers
+ 1
for (int i = 0; i < (nElements - 1); i++) { for (int j = (i + 1); j < nElements; j++) { if (array[ j ] == array[ i ]) num++; } countingArray[ i ] = num; } I think this will do what you're asking for? then just use a bubble sorter to find which one occurs the most
21st Oct 2016, 6:17 AM
Zeke Williams
Zeke Williams - avatar
+ 1
sorry, this is not correct for your question. You will need a nested for loop, most likely though. the code I gave you will recount elements. if you know exactly which values will occur more than once, it would be much easier. I also have some code for determining the amount of times a letter appears in a char array.
21st Oct 2016, 8:07 PM
Zeke Williams
Zeke Williams - avatar