java四种常用排序冒泡排序选择排序插入排序快速排序

import java.util.Arrays;

/**
 * Created by Admin on 2018/3/31.
 */
public class Sort {

    public static void main(String[] args) {
        int a[] = {3,1,5,7,2,4,9,6,10,8};
        System.out.println("排序后:"+ Arrays.toString(bubbleSort(a)));
        System.out.println("排序后:"+ Arrays.toString(selectSort(a)));
        System.out.println("排序后:"+ Arrays.toString(insertSort(a)));
        System.out.println("排序后:"+ Arrays.toString(quickSort(a,0, a.length - 1)));
    }

    public static int[] bubbleSort(int a[]) {
        int temp;
        for(int i=0;ia[j+1]) {
                    temp = a[j];
                    a[j] = a[j+1];
                    a[j+1] = temp;
                }
            }
        }
        return a;
    }

    public static int[] selectSort(int[] a) {
        int length = a.length;
        for(int i=0;i0 && x base) && (j > start))
                    j--;
                if (i <= j) {
                    temp = a[i];
                    a[i] = a[j];
                    a[j] = temp;
                    i++;
                    j--;
                }
            } while (i <= j);
            if (start < j)
                quickSort(a, start, j);
            if (end > i)
                quickSort(a, i, end);
        }
        return a;
    }
}

你可能感兴趣的:(java)