摘要:
/** * * 改进后的归并排序: * */ public class ImprovedMergeSort { private static final int THRESHOLD = 10; public void sort(int[] data) { int[] temp = new int[data.length]; mergeSort(data, temp, 0, data.length - 1); } private void mergeSort(int[] data, int[] ... 阅读全文
摘要:
/** * * 堆排序: * */ public class HeapSort { public void sort(int[] data) { MaxHeap h = new MaxHeap(); h.init(data); for (int i = 0; i queue[j]) // 不用交换 break; swap(queue, j, k); k = j; } ... 阅读全文
摘要:
public class BubbleSort { public void sort(int[] data) { for (int i = 0; i i; j--) { if (data[j] < data[j - 1]) { swap(data, j, j - 1); } } } } private void swap(int[] data, int i, int j) { ... 阅读全文
摘要:
/** * 改进后的快速排序: * */ public class ImprovedQuickSort { private static int MAX_STACK_SIZE = 4096; private static int THRESHOLD = 10; public void sort(int[] data) { int[] stack = new int[MAX_STACK_SIZE]; int top = -1; int pivot; int pivotInd... 阅读全文
摘要:
/** * 插入排序: * */ public class InsertSort { public void sort(int[] data) { for (int i = 1; i 0) && (data[j] < data[j - 1]); j--) { swap(data, j, j - 1); } } } private void swap(int[] data, int i, int j) { int temp =... 阅读全文
摘要:
/** * 选择排序: * */ public class SelectionSort { public void sort(int[] data) { for (int i = 0; i i; j--) { if (data[j] < data[lowIndex]) { lowIndex = j; } } swap(data, i, lowIndex); } }... 阅读全文