Java implements quicksort methods

  • 2020-04-01 03:52:43
  • OfStack

This article illustrates a Java method for quicksort. Share with you for your reference. The specific implementation method is as follows:


public class Quick {
 public static int[] Data = { 9, 8, 7, 4, 1, 12, 15, 63, 15, 20 };
 public static void quick(int left, int right) {
 int i, j;
 int Pivot;
 int temp;
 i = left;
 j = right;
 Pivot = Data[(left+right)/2];
 while (i < j) {
  while (Data[i] < Pivot)i++;
  while (Data[j] > Pivot) j--;
  if (i <= j) {
  temp = Data[i];
  Data[i] = Data[j];
  Data[j] = temp;
  i++;
  j--;
  }
 }
 if (left < j)
  quick(left, j);
 if (i < right)
  quick(i, right);
 }
 public static void main(String[] args) {
 System.out.println("aaa");
 quick(0, 9);
 System.out.println("bbb");
 for (int a = 0; a < Data.length; a++) {
  System.out.print(Data[a] + " ");
 }
 }
}

I hope this article has been helpful to your Java programming.


Related articles: