title: Implementing QuickSort With middle element as Pivot
body: <p>I tried and wrote a code for Quicksort with middle element as pivot.</p>
  
  <p>I was successful in writing one.</p>
  
  <p>But Pivot has the property that:</p>
  
  <p>Elements on its left are lesser than pivot and greater on its right.</p>
  
  <p>I was not able to achieve this in my following code.</p>
  
  <pre><code>private static void QuickSortAlgorithm(int[] a, int i, int n) 
  {
      if(i&lt;n)
      {
          int part = partition(a,i,n);
  
          QuickSortAlgorithm(a, i, part-1);
  
          QuickSortAlgorithm(a, part, n);
      }
  }
  
  private static int partition(int[] a, int i, int n) 
  {
      int pivot = (i+n)/2;
  
      int left = i;
  
      int right = n;
      while(left&lt;=right)
      {
          while(a[left]&lt;a[pivot]){
              left++;
          }
  
          while(a[right]&gt;a[pivot])
          {
              right--;
          }
  
          if(left&lt;=right)
          {
              swap(a,left,right);
              left++;
              right--;
          }
      }
      return left;
  
  }
  </code></pre>
  
  <p>Main Method:    </p>
  
  <pre><code>    int a[]={5,7,3,9,1};
      int n = a.length;
      QuickSortAlgorithm(a,0,n-1);
      System.out.println(Arrays.toString(a));
  </code></pre>
  
  <p>My doubt is:</p>
  
  <p>I am sending left as my partitioned index.</p>
  
  <p>But, when I am recursively calling QuickSortAlgorithm()</p>
  
  <p>I am sending <code>i to part-1</code> and <code>part to n</code>;</p>
  
  <p>What should I send as partition index so that </p>
  
  <p>I could call something like this: So that pivot property is satisfied?</p>
  
  <pre><code>    QuickSortAlgorithm(a, i, part-1);
  
      QuickSortAlgorithm(a, part+1, n);
  </code></pre>
  
  <p>Thank you:)</p>