快速排序
import java. util. Scanner;
public class quickSortReference {
public static void main ( String[ ] args) {
Scanner scanner = new Scanner ( System. in) ;
String[ ] split = scanner. nextLine ( ) . split ( "," ) ;
int array[ ] = new int [ split. length] ;
for ( int i = 0 ; i < split. length; i++ ) {
array[ i] = Integer. parseInt ( split[ i] ) ;
}
array = quickSort ( array) ;
for ( int i : array) {
System. out. print ( i + " " ) ;
}
}
public static int [ ] quickSort ( int [ ] array) {
if ( array. length <= 0 ) {
return null;
}
quickSort ( array, 0 , array. length - 1 ) ;
return array;
}
public static void quickSort ( int [ ] array, int left, int right) {
int i = left;
int j = right;
int pivot = array[ ( left + right) / 2 ] ;
while ( i <= j) {
while ( pivot > array[ i] ) {
i++ ;
}
while ( pivot < array[ j] ) {
j-- ;
}
if ( i <= j) {
int temp = array[ i] ;
array[ i] = array[ j] ;
array[ j] = temp;
i++ ;
j-- ;
}
}
if ( left < j) {
quickSort ( array, left, j) ;
}
if ( i < right) {
quickSort ( array, i, right) ;
}
}
}