the fast way to find a duplicated items in array

 

Hello,

 

can someone tell me what is the fast and best way to find a duplicated/or more items in array in MQL4 ?

 

thanks 

 
sort the array and compare the neighbours
 
Use array sorting and find if a value is duplicated. Easy with loops.
 
Rohi Finish:

Hello,

 

can someone tell me what is the fast and best way to find a duplicated/or more items in array in MQL4 ?

 

thanks 

Use my function.


/**
* Returns most repeated value from array
* @param double array
* @return double
*/
double GetMostRepeatedFromArray(double &arr[])
{
   double unique[] = {};
   double hits[] = {};
   for(int i = 0; i < ArraySize(arr); i++)
   {
      int index = ArrayFind(unique, arr[i]);
      if(index == WRONG_VALUE)
      {
         int size = ArraySize(unique);
         ArrayResize(unique, size+1);
         ArrayResize(hits, size+1);
         unique[size] = arr[i]; 
         hits[size] = 1;
      } else {
         hits[index] = hits[index] + 1;
      }
   }
   return(unique[ArrayMaximum(hits)]);
}

int ArrayFind(double &arr[], double value)
{
   for(int i = 0; i < ArraySize(arr); i++)
   {
      if(arr[i] == value) return(i);
   }
   return(WRONG_VALUE);
}


Reason: