A classe de ferramentas resume breve e claramente cinco algoritmos de classificação de Java: classificação rápida, classificação de montanhas, classificação de inserção, classificação de heap e classificação de mesclagem. Não há explicação para esses algoritmos de classificação no código. Espero verificar as instruções relevantes para a parte do pensamento sozinha. Aqui só resumirei esses algoritmos para todos usarem.
classe pública classificar {public static <Anytype estende comparável <?? Super AnyType >> INSERÇÃO VOID (AnyType [] a) {Insertionsort (A, 0, A.Length - 1); } estática privada <anytype estende comparável <?? Super AnyType >> INSERÇÃO VOID (anytype [] a, int esquerd, int direita) {int j; // Registre a posição do seguinte dígito do primeiro elemento menor que o TMP para (int p = esquerda; p <= direita; p ++) {anytype tmp = a [p]; for (j = p; j> esquerda && tmp.compareto (a [j - 1]) <0; j--) {a [j] = a [j - 1]; } a [j] = tmp; }} public static <anytype estende comparável <?? Super AnyType >> void Shellsort (Anytype [] arr) {int j; for (int gap = arr.length / 2; gap> 0; gap / = 2) {for (int i = gap; i <arr.length; i ++) {anytype tmp = arr [i]; para (j = i; j> = gap && tmp.compareto (arr [j - gap]) <0; j - = gap) {arr [j] = arr [j - gap]; } arr [j] = tmp; }}} private static int leutchild (int i) {return i * 2 + 1; } estática privada <anytype estende comparável <?? Super AnyType >> void perculadown (Anytype [] arr, int i, int size) {Anytype tmp = arr [i]; para (int filho; (filho = leftChild (i)) <tamanho; i = filho) {if (filho! } if (tmp.compareto (arr [filho]) <0) {arr [i] = arr [filho]; } else {break; }} arr [i] = tmp; } public static <anytype se estende comparável <?? Super AnyType >> void heapset (Anytype [] arr) {for (int i = arr.length / 2; i> = 0; i--) {perculadown (arr, i, arr.length); } para (int i = arr.length-1; i> = 0; i--) {swapreferências (arr, 0, i); perculadown (arr, 0, i); }} estática privada <anytype estende comparável <?? Super AnyType >> SwapReferências void (Anytype [] arr, int i, int j) {Anytype tmp = arr [i]; arr [i] = arr [j]; arr [j] = tmp; } public static <anytype se estende comparável <?? Super AnyType >> void mescort (Anytype [] arr) {anytype [] tmp = ((anytype []) novo comparável [arr.length]); Mergesort (arr, 0, arr.length - 1, tmp); } estática privada <anytype estende comparável <?? Super AnyType >> void mesmort (Anytype [] arr, int start, int end, Anytype [] tmp) {if (start <end <end <end) {int mid = (start + end) >> 1; mesclar (ARR, Start, Mid, TMP); Mergesort (ARR, MID + 1, END, TMP); mesclar (arr, start, médio, final, tmp); }} estática privada <anytype estende comparável <?? 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 ++]; } para (int m = start; m <= end; m ++) {arr [m] = tmp [m]; }} public static <anytype estende comparável <?? Super AnyType >> Void Quicksort (Anytype [] arr) {QuickSort (arr, 0, arr.length - 1); } estática privada <anytype estende comparável <?? Super AnyType >> void QuickSort (Anytype [] arr, int esquerd, int direita) {if (esquerda + comprimento_diff <= direita) {Anytype pivot = médio (arr, esquerda, direita); int i = esquerda, j = direita; while (true) {while (arr [++ i] .compareto (pivot) <0); while (arr [-j] .compareto (pivô)> 0); if (i <j) {swapreferências (arr, i, j); } else {break; }} SwapReferences (arr, i, direita); Quicksort (arr, à esquerda, i - 1); Quicksort (arr, i + 1, à direita); } else {inserttionsort (arr, esquerda, direita); }} estática privada <anytype estende comparável <?? Super AnyType >> AnyType Medium (Anytype [] arr, int esquerd, int direita) {int Center = (esquerda + direita) / 2; if (arr [Center] .compareto (arr [esquerda]) <0) {swapreferências (arr, centro, esquerda); } if (arr [esquerda] .compareto (arr [direita])> 0) {swapreferências (arr, esquerda, direita); } if (arr [Center] .compareto (arr [direita]) <0) {swapreferências (arr, centro, direita); } retornar arr [direita]; } private final static int length_diff = 20;}O exposto acima é todo o conteúdo deste artigo. Espero que seja útil para o aprendizado de todos e espero que todos apoiem mais o wulin.com.