title: Find solution to sort the array which scans the array once
body: <pre><code>package recursion;
  public class QuickSort {
  
  public static void quickSort(int[] input,int beginIndex,int endIndex)
  {
      if(beginIndex&gt;=endIndex)
      {
          return;
      }
  
      int pivotIndex = partition(input,beginIndex,endIndex);
  
      quickSort(input, beginIndex, pivotIndex-1);
  
      quickSort(input, pivotIndex+1, endIndex);
  }
  
  public static int partition(int[] input,int beginIndex,int endIndex)
  {
      int count = 0;
      int pivotElement = input[beginIndex];
      for(int i = beginIndex+1;i&lt;=endIndex;i++)
      {
          if(pivotElement &gt;= input[i])
              count++;
      }
  
      int temp2 = beginIndex;
  
  
      int temp = pivotElement;
      input[beginIndex] = input[count+beginIndex];
      input[count+beginIndex] = temp;
  
      while(beginIndex &lt; endIndex)
      {
          if(input[beginIndex] &lt;= pivotElement)
          {
  
              beginIndex++;
          }
          else if(input[endIndex]&gt;pivotElement)
          {
  
              endIndex--;
          }
  
          else            
          {
              int temp3 = input[beginIndex];
              input[beginIndex] = input[endIndex];
              input[endIndex] = temp3;
  
          }
      }
  
      return temp2 + count;
  
  
  }
  
  public static void main(String[] args) {
      // TODO Auto-generated method stub
  
      int[] n = {0,1,0,2,2,1,1,0};
      quickSort(n, 0, 7);
  
      for(int i = 0;i&lt;=7;i++)
      {
          System.out.println(n[i]);
      }
  
  }
  
  }
  </code></pre>
  
  <p>Given an array containing only 0’s, 1’s and 2’s, I want to set my pivot element to be equal to 1 so that all the 0s comes before it and all the 2s comes after it
  this way it will only scan the array once.
  But I am not able to set my pivot element to be 1</p>
  
  <p>So please help me in solving this!</p>