<>学习数据结构的重要性

<>算法复杂度比较

<>数据结构重点：排序算法比较

<>为什么要综合比较

<>插入排序

public static int[] insertSort(int[] sourceArray) { int s; int temp; for (int
i = 1; i < sourceArray.length; i++) { temp = sourceArray[i]; s = i; while (s >
0 && temp < sourceArray[s - 1]) { sourceArray[s] = sourceArray[s - 1]; s = s -
1; } sourceArray[s] = temp; } return sourceArray; }
<>交换排序
<>冒泡排序

private static int[] bubbleSort(int[] sourceArray) { for (int i = 0; i <
sourceArray.length; i++) { for (int j = 0; j < sourceArray.length - 1; j++) {
sortMaxAndPutItRight(sourceArray, j, j+1); } } return sourceArray; } private
static void sortMaxAndPutItRight(int[] sourceArray, int left, int right) { if
(sourceArray[left] > sourceArray[right]) { int temp = sourceArray[right];
sourceArray[right] = sourceArray[left]; sourceArray[left] = temp; } } <>快速排序

——

public static int[] quickSort(int[] sourceArray, int start, int end) { if
(start < end) { int index = sortAndFindIndex(sourceArray, start, end);
quickSort(sourceArray, start, index - 1); quickSort(sourceArray, index + 1,
end); } return sourceArray; } private static int sortAndFindIndex(int[]
sourceArray, int start, int end) { int temp = sourceArray[start]; while (start
< end) { while ((sourceArray[end] >= temp) && (start < end)) { end --; }
sourceArray[start] = sourceArray[end]; while ((sourceArray[start] <= temp) &&
(start < end)) { start ++; } sourceArray[end] = sourceArray[start]; }
sourceArray[start] = temp; return start; }
<>选择排序
<>简单选择排序

public static int[] selectionSort(int[] sourceArray) { for (int i = 0; i <
sourceArray.length - 1; i++) { int min = i; for (int j = i + 1; j <
sourceArray.length; j++) { min = sourceArray[j] < sourceArray[min] ? j : min; }
swap(sourceArray, i, min); } return sourceArray; } private static void
swap(int[] arr, int i, int j) { int temp = arr[i]; arr[i] = arr[j]; arr[j] =
temp; } <>堆排序

<>基数排序

public static int getNumInPos(int num, int pos) { int tmp = 1; for (int i = 0;
i < pos - 1; i++) { tmp *= 10; } return (num / tmp) % 10; } public static int
getMaxDigit(int[] a) { int max = a[0]; for (int i = 0; i < a.length; i++) { if
(a[i] > max) { max = a[i]; } } int tmp = 1, d = 1; while (true) { tmp *= 10; if
(max / tmp != 0) { d++; } else { break; } } return d; } public static void
radixSort(int[] a, int d) { int[][] array = new int[10][a.length + 1]; for (int
i = 0; i < 10; i++) { array[i][0] = 0; } for (int pos = 1; pos <= d; pos++) {
for (int i = 0; i < a.length; i++) { int row = getNumInPos(a[i], pos); int col
= ++array[row][0]; array[row][col] = a[i]; } for (int row = 0, i = 0; row < 10;
row++) { for (int col = 1; col <= array[row][0]; col++) { a[i++] =
array[row][col]; } array[row][0] = 0; } } }
<>计数排序

private static int[] countSort(int[] array) { int maxVal =
Arrays.stream(array).max().getAsInt(); int[] sortList = new int[maxVal + 1];
for (int i : array) { sortList[i]++; } int sortedIndex = 0; for (int i = 0; i <
(maxVal + 1); i++) { while (sortList[i] > 0) { array[sortedIndex++] = i;
sortList[i]--; } } return array; }
<>归并排序
<>二路归并排序

<>推荐书籍

《数据结构教程(第三版)》