In order to find the most occurent element I am using:
int find( int* arr, int size )
{
int count = 0, MostOc;
for ( int i = 0; i < size; i++ )
{
if ( count == 0 )
{
MostOc = arr[i];
}
if ( arr[i] == MostOc )
count++;
else
count--;
}
return MostOc;
}
I can't figure how to return also the positions where the value of the most occurence element is .
For example,for the following code , I should receive that the most occurent element is 14 and it is found at positions 0,4,7,8,12,13,16,17.
#include <stdio.h>
#include <stdlib.h>
int find( int* arr, int size Arr )
{
int count = 0, MostOc;
for ( int i = 0; i < sizeArr; i++ )
{
if ( count == 0 )
{
MostOc = arr[i];
}
if ( arr[i] == MostOc )
count++;
else
count--;
}
return MostOc;
}
int main()
{
int arr[] = { 14,10, 2, 1,14,1,10,14,14,2,3,4,14,14,1,4,14,14 };
int N = 18;
printf("res = %d\n",find(arr,N) );
return 0;
}