title: Quicksort With a Comparator
body: <p>i'am working on project to Sort an array of Student objects with the following critiria:</p>
  
  <p>1.Sort grades</p>
  
  <p>2.If grades are equal, sort on StudentNumber.</p>
  
  <p>now i got this working using the Arrays.Sort(T[] a, Comparator&lt;> c ) method.
  since i think this sorting method is to slow, i want to use Quicksort.</p>
  
  <p>i got the following piece of code:</p>
  
  <pre><code>public static void quickSort(Student[] arr, int low, int high) {
      if (arr == null || arr.length == 0) {
          return;
      }
      if (low &gt;= high) {
          return;
      }
      // pick the pivot
      int middle = low + (high - low) / 2;
      Student pivot = arr[middle];
      // make left &lt; pivot and right &gt; pivot
      int i = low, j = high;
      while (i &lt;= j) {
          while (arr[i].getCijfer() &lt; pivot.getCijfer()) {
              i++;
          }
          while (arr[j].getCijfer() &gt; pivot.getCijfer()) {
              j--;
          }
          if (i &lt;= j) {
              Student temp = arr[i];
              arr[i] = arr[j];
              arr[j] = temp;
              i++;
              j--;
          }
      }
      // recursively sort two sub parts
      if (low &lt; j) {
          quickSort(arr, low, j);
      }
      if (high &gt; i) {
          quickSort(arr, i, high);
      }
  }
  </code></pre>
  
  <p>UPDATE Comparator Code:</p>
  
  <pre><code>private static Comparator&lt;Student&gt; gradeComparator = new Comparator&lt;Student&gt;() {
      @Override
      public int compare(Student o1, Student o2) {
          int compareTo = 0;
          if (o1.cijfer &gt; o2.cijfer) {
              compareTo = -1;
          } else {
              if (o1.cijfer &lt; o2.cijfer) {
                  compareTo = 1;
              } else {
                  // als Studenten Grade gelijk, vergelijk op studenten Ldap
                  if (o1.cijfer == o2.cijfer) {
                      if (o1.studentnummer &gt; o2.studentnummer) {
                          compareTo = -1;
                      } else {
                          compareTo = 1;
                      }
                  }
              }
          }
          return compareTo;
      }
  };
  </code></pre>
  
  <p>this sorts the array on the Grades(cijfer) but i'am stuck on where to put my 2nd sorting criteria. please help me!</p>
  
  <p>Kind regards</p>