툴 클래스는 Java의 5 가지 정렬 알고리즘의 빠른 분류, 힐 정렬, 삽입 분류, 힙 정렬 및 병합 분류를 간단히 그리고 명확하게 요약합니다. 코드에 이러한 분류 알고리즘에 대한 설명은 없습니다. 아이디어 부분에 대한 관련 지침을 직접 확인하고 싶습니다. 여기에서는 모든 사람이 사용할 수 있도록 이러한 알고리즘 만 요약하겠습니다.
공개 클래스 정렬 {public static <AnyType는 비슷한 <? 슈퍼 anytype >> void insertionsort (anytype [] a) {insertionsort (a, 0, a.length -1); } private static <AnyType는 비슷한 <? Super AnyType >> void insertionsort (AnyType [] a, int left, int right) {int j; // tmp보다 작은 첫 번째 요소의 다음 숫자의 위치를 기록합니다 (int p = left; p <= right; p ++) {anytype tmp = a [p]; for (j = p; j> left && tmp.compareto (a [j -1]) <0; j-) {a [j] = a [j -1]; } a [j] = tmp; }} public static <AnyType는 비슷한 <? 슈퍼 anytype >> void shellsort (anytype [] arr) {int j; for (int gap = Ar for (j = i; j> = gap && tmp.compareto (arr [j -gap]) <0; j- = gap) {arr [j] = arr [j -gap]; } arr [j] = tmp; }}} private static int leftchild (int i) {return i * 2 + 1; } private static <AnyType는 비슷한 <? 슈퍼 anytype >> void perculations (anytype [] arr, int i, int size) {anytype tmp = arr [i]; for (int child; } if (tmp.compareto (arr [child]) <0) {arr [i] = arr [child]; } else {break; }} arr [i] = tmp; } public static <AnyType는 비슷한 <? Super AnyType >> void Heapsort (anyType [] arr) {for (int i = arr.length / 2; i> = 0; i-) {퍼센스 (Arr, i, arr.length); } for (int i = arr.length-1; i> = 0; i-) {swapreferences (arr, 0, i); 오염 된 (ARR, 0, i); }} private static <AnyType는 비슷한 <? 슈퍼 anytype >> void swapreferences (anyType [] arr, int i, int j) {anyType tmp = arr [i]; arr [i] = arr [j]; ARR [J] = TMP; } public static <AnyType는 비슷한 <? super anytype >> void mergesort (anyType [] arr) {anyType [] tmp = ((anyType []) 새로운 비교 [arr.length]); MERGESORT (ARR, 0, ARR.LENGTH -1, TMP); } private static <AnyType는 비슷한 <? Super AnyType >> void mergesort (anyType [] arr, int start, int end, anyType [] tmp) {if (start <end) {int mid = (start + end) >> 1; Mergesort (ARR, Start, Mid, TMP); Mergesort (ARR, MID + 1, END, TMP); 병합 (ARR, 시작, 중간, 끝, TMP); }} private static <AnyType는 비슷한 <? Super AnyType >> void merge (anyType [] arr, int start, int mid, int end, anytype [] tmp) {int i = start, j = mid + 1, k = start; while (i <= mid && j <= end) {if (arr [i] .compareto (arr [j]) <0) {tmp [k ++] = arr [i ++]; } else {tmp [k ++] = arr [j ++]; }} while (i <= mid) {tmp [k ++] = arr [i ++]; } while (j <= end) {tmp [k ++] = arr [j ++]; } for (int m = start; m <= end; m ++) {arr [m] = tmp [m]; }} public static <AnyType는 비슷한 <? Super AnyType >> void QuickSort (anyType [] arr) {QuickSort (arr, 0, arr.length -1); } private static <AnyType는 비슷한 <? Super AnyType >> void QuickSort (anyType [] arr, int left, int right) {if (left + longth_diff <= right) {anyType pivot = medium (arr, 왼쪽, 오른쪽); int i = 왼쪽, j = 오른쪽; while (true) {while (arr [++ i] .compareto (pivot) <0); while (arr [-j] .compareto (pivot)> 0); if (i <j) {swapreferences (arr, i, j); } else {break; }} swapreferences (arr, i, 오른쪽); QuickSort (ARR, LEFT, I -1); QuickSort (arr, i + 1, 오른쪽); } else {insertionsort (arr, 왼쪽, 오른쪽); }} private static <AnyType는 비슷한 <? 슈퍼 anytype >> anyType 매체 (anyType [] arr, int left, int right) {int center = (왼쪽 + 오른쪽) / 2; if (arr [center] .compareto (arr [left]) <0) {swapreferences (arr, center, left); } if (arr [left] .compareto (arr [오른쪽]> 0) {swapreferences (arr, 왼쪽, 오른쪽); } if (arr [center] .compareto (arr [오른쪽]) <0) {swapreferences (arr, center, right); } return arr [오른쪽]; } 개인 최종 정적 int longth_diff = 20;}위는이 기사의 모든 내용입니다. 모든 사람의 학습에 도움이되기를 바랍니다. 모든 사람이 wulin.com을 더 지원하기를 바랍니다.