import java.util.Scanner; /** * @author 杨川 * */ public class Sort { public static void main(String[] args) { int a[] = input(); insertSort(a); shellSort(a); selectSort(a); fastSort(a,0,a.length-1); for (int k = 0; k < a.length; k++) { System.out.print(a[k] + " "); } } static void fastSort(int[]a,int s,int t){ int i=s; int j=t; if (si&&a[j]>=last){ j--; } a[i]=a[j]; while(i= 0 && temp < a[j]) { // 比前面的小的话元素逐个往后移,直到找到不小于它的位置(正确位置) a[j + 1] = a[j]; j--; } a[j + 1] = temp; } for (int i = 0; i < a.length; i++) { System.out.print(a[i] + " "); } return a; } static int[] shellSort(int a[]) { int gap = a.length/2; while (gap > 0) { // int gap=5; for (int i = gap; i < a.length; i++) { int temp = a[i]; int j = i - gap; while (j >= 0 && temp < a[j]) { a[j + gap] = a[j]; j -= gap; } a[j + gap] = temp; } gap = gap/2; } for (int i = 0; i < a.length; i++) { System.out.print(a[i] + " "); } return a; } static int[] input() { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = scanner.nextInt(); } return a; } }