title: median 3 quick sort implementation
body: <p>my median 3 implementation is not working fine here. i have to choose 3 numbers randomly for medium here is my code please help me.</p>
  
  <pre><code>#include"stdafx.h"
  #include &lt;iostream&gt;
  #include&lt;algorithm&gt;
  using namespace std;
  #define size 10
  int i;                               
  void show(int* array, int n);
  int partition(int* array, int pValue, int left, int right);
  void QuickSort(int* array, int left, int right);
  
  int main(void)
  {
      int array[size];
      int i;
  
      for( i = 0; i &lt; size; i++)              
      {
           array[i]=rand()%100;
      }
  
      cout&lt;&lt;endl&lt;&lt;"The random generated numbers are: "&lt;&lt;endl;
      show(array, size);
      QuickSort(array,0,size - 1);                
      cout&lt;&lt;endl&lt;&lt;"The sorted numbers are : "&lt;&lt;endl;
      show(array, size);
  
      system("pause");
      return 0;
  }
  
  void show(int* array, int n)
  {
      int i;
  
      for( i = 0; i &lt; n; i++) cout&lt;&lt;array[i]&lt;&lt;'\t';
  }
  
  
  
  void QuickSort(int* array, int left, int right)
  {
      for(i=0;i&lt;3;i++)
      {
         array[i]=array[rand()%100];
        }
        stable_sort(array,array+3);
       int p=array[(i+1)/2];
      //int p = array[left];              
      int split;
  
      if(right &gt; left)                         
      {
          split = partition(array, p, left, right);
  
          array[split] = p;
          QuickSort(array, left, split-1);   
          QuickSort(array, split+1, right);    
      }
  }
  
  
  int partition(int* array, int p, int left, int right)
  {
      int lb = left;
      int rb = right;
  
      while(lb &lt; rb)             
      {
           while( p &lt; array[rb]&amp;&amp; rb &gt; lb)      
           {
                rb--;                     
           }
           swap(array[lb], array[rb]);
  
           while( p &gt;= array[lb]&amp;&amp; lb &lt; rb)     
           {
                lb++;                      
           }
           swap(array[rb], array[lb]);
  
      }
      return lb;                            
  
  
  }
  </code></pre>