标签:arrays port void import ++ sort return static ret
import java.util.Arrays; public class QuickSort { public static void main(String[] args) { int[] a = { 34, 1, 99, 44, 89, 42, 31, 6, 3 }; System.out.println(Arrays.toString(a)); quickSort(a, 0, a.length - 1); System.out.println(Arrays.toString(a)); } public static void quickSort(int[] arr, int left, int right) { if (left >= right) { return; } int i = left; int j = right; int key = arr[left]; while (i < j) { while (i < j && arr[j] > key) {// 这两个while不能交换 j--; } arr[i] = arr[j]; while (i < j && arr[i] < key) { i++; } arr[j] = arr[i]; } arr[i] = key; quickSort(arr, i + 1, right); quickSort(arr, left, i - 1); } }
标签:arrays port void import ++ sort return static ret
原文地址:http://www.cnblogs.com/Tan-Yin-Yin-19971130/p/7956144.html