title: How to make pivot element generic inside Quicksort?
body: <p>I am trying to sort 100k elements present in a file using quicksort.My algorithm works only if I use first element as pivot.How can I make pivot element generic to the program?What is the best way to choose a pivot element using quicksort?Is pivot element dependent on the data or do we use any specific algorithms in real time?</p>
  
  <pre><code>void quicksort(int *temp,int p,int r)
  {
      if(r &gt; p + 1)
      {
          int piv = temp[p];
          int left = p + 1;
          int right = r;
          while(left &lt; right)
          {
              if(temp[left] &lt;= piv)
                  left++;
              else
                  swap(&amp;temp[left], &amp;temp[--right]);
          }
          swap(&amp;temp[--left], &amp;temp[p]);
          quicksort(temp, p, left);
          quicksort(temp, right, r);
      }
  }
  </code></pre>