데이터 구조정렬01

정렬 선택
    /**
     *      
     * <p>1、     </p>
     * @param array
     */
    public void selectSort(int[] array) {
        for (int i = 0; i < array.length - 1; i++) {
            int tmp = i;
            for (int j = i + 1; j < array.length; j++) {
                if (array[tmp] > array[j]) {
                    tmp = j;
                }
            }
            if (tmp != i) {
                int tmpV = array[tmp];
                array[tmp] = array[i];
                array[i] = tmpV;
            }
            System.out.println("I: " + i + ";J: " + tmp + " arr:" + Arrays.toString(array));
        }
    }

거품 정렬
    /**
     *     
     * <p>1、     </p>
     * @param a        
     */
    public void sortB(int[] array) {
        for (int i = array.length - 1; i >= 1; i--) {
            for (int j = 0; j < i; j++) {
                if (array[j] > array[j + 1]) {
                    int tmp = array[j];
                    array[j] = array[j + 1];
                    array[j + 1] = tmp;
                }
                System.out.println("I:" + i + "J: " + j + " arr:" + Arrays.toString(array));
            }
        }
    } 

삽입 정렬
    /**
     *     
     * @param array
     */
    public void insertSort(int[] array) {
        int in = 0, out = 0;
        for (out =1; out < array.length; out++) {
            int tmp = array[out];
            in = out;
            while (in > 0 && array[in - 1] >= tmp) {
                array[in] = array[in - 1];
                --in;
            }
            array[in] = tmp;
            System.out.println("in: " + in + " out: " + out + " array: " + Arrays.toString(array));
        }
        System.out.println("in: " + in + " out: " + out + " array: " + Arrays.toString(array));
    }

좋은 웹페이지 즐겨찾기