今天心血来潮,想练练自己的基本功,就写了快排程序,唯一注意的一点就是
System.out.print(a[i]+‘ ’);如果a[i]为整数,那么这个输出的结果将是空格的ascII码,空格与字符串相连接时才会输出空格。import java.util.*; public class QuickSort { /** * @param args */ static void quickSort(int[] a, int front, int rear) { if(front<rear) { int flag = rear; int temp = a[flag]; int p = front; int q = rear; while (p<q) { while (a[p] <= temp && p < q) { p++; } a[q] = a[p]; while (a[q] >= temp && q > p) { q--; } a[p] = a[q]; } int mid=p; a[p] = temp; quickSort(a, front, mid-1); quickSort(a, mid+1, rear); } } public static void main(String[] args) { // TODO Auto-generated method stub int[] a={3,2,1,4}; quickSort(a,0,a.length-1); for(int i=0;i<a.length;i++){ System.out.print(a[i]); } } }