标签:style blog color io ar for art div sp
package com.rainfool.quicksort; public class Test2 { public static void main(String[] args) { Integer[] a = { 2, 8, 7, 1, 3, 5, 6, 4 }; quickSort(0, a.length - 1, a); for (int i = 0; i < a.length; i++) { System.out.print(a[i] + " "); } } public static <T extends Comparable<? super T>> void quickSort(int p, int r, T[] A) { if (p < r) { int q = partition(p, r, A); quickSort(p, q - 1, A); quickSort(q + 1, r, A); } } public static <T extends Comparable<? super T>> int partition(int p, int r, T[] A) { int i = p - 1; for (int j = p; j < r; j++) { if (A[j].compareTo(A[r]) < 0) { i++; T t = A[j]; A[j] = A[i]; A[i] = t; } } T t = A[i + 1]; A[i + 1] = A[r]; A[r] = t; return i + 1; } }
标签:style blog color io ar for art div sp
原文地址:http://www.cnblogs.com/RainFool/p/3953120.html