title: Find most frequent and median values in array C++
body: <p>I want to find the most frequent and median values of a given array by using C++. I assume that I have a float array such as </p>
  
  <pre><code>float *LRArr=new LRArr[1000];
  </code></pre>
  
  <p>The array is filled by random float number.</p>
  
  <pre><code>std::default_random_engine generator;
  generator.seed( rd() );
  std::uniform_real_distribution&lt;&gt; distribution(0, 10);
  for(int j=0;j&lt;1000;j++)
  {
      LRArr[j]=distribution(generator)
  }
  </code></pre>
  
  <p>Now I want to get the most frequent values in the array. But it take many time. Could you suggest to me the faster way to implemt it by C or C++? I assume I have the <code>LRArr</code> such as</p>
  
  <pre><code>LRArr={0.1,1.2,6.5,6.5,4.5,6.5}
  ==&gt;output is: 6.5 and median 5.5
  </code></pre>
  
  <p>This is my way:</p>
  
  <pre><code>float getMostFreq(float* LRArr;int sizeLRArr)
  {
  int count = 1;
  int currentIndex = 0;
     for (int i = 1; i &lt; sizeLRArr; i++)
     {
      if (LRArr[i] == LRArr[currentIndex])
          count++;
      else
          count--;
      if (count == 0)
      {
          currentIndex = i;
          count = 1;
      }
    }
    mostFreq = LRArr[currentIndex];
    return mostFreq;
  } 
  </code></pre>