├── README.md ├── BubbleSort.java ├── HeapSort.java ├── InsertSort.java ├── MergeSort1.java ├── QickSort.java ├── SelectSort.java ├── BinarySearch.java ├── MergingSort.java ├── MergingSort1.java ├── InsertSortByBinary.java ├── InsetSortTest.java ├── InsertSortByBinaryTest.java ├── ShowPro.java ├── QickSortTest.java └── InsertHillSort.java /README.md: -------------------------------------------------------------------------------- 1 | # Sort 2 | 排序算法 3 | -------------------------------------------------------------------------------- /BubbleSort.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deserialization/Sort/master/BubbleSort.java -------------------------------------------------------------------------------- /HeapSort.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deserialization/Sort/master/HeapSort.java -------------------------------------------------------------------------------- /InsertSort.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deserialization/Sort/master/InsertSort.java -------------------------------------------------------------------------------- /MergeSort1.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deserialization/Sort/master/MergeSort1.java -------------------------------------------------------------------------------- /QickSort.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deserialization/Sort/master/QickSort.java -------------------------------------------------------------------------------- /SelectSort.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deserialization/Sort/master/SelectSort.java -------------------------------------------------------------------------------- /BinarySearch.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deserialization/Sort/master/BinarySearch.java -------------------------------------------------------------------------------- /MergingSort.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deserialization/Sort/master/MergingSort.java -------------------------------------------------------------------------------- /MergingSort1.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deserialization/Sort/master/MergingSort1.java -------------------------------------------------------------------------------- /InsertSortByBinary.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deserialization/Sort/master/InsertSortByBinary.java -------------------------------------------------------------------------------- /InsetSortTest.java: -------------------------------------------------------------------------------- 1 | package cn.it.sort; 2 | 3 | public class InsetSortTest { 4 | public static void insertSortTest(int []array) { 5 | int i,j; 6 | int temp; 7 | for (i = 1; i < array.length; i++) { 8 | if (array[i] < array[i - 1]) { 9 | temp = array[i]; 10 | for (j = i - 1; j >= 0 && array[j] > temp; j--) { 11 | array[j + 1] = array[j]; 12 | } 13 | array[j + 1] = temp; 14 | } 15 | } 16 | 17 | } 18 | public static void main(String[] args) { 19 | int array[] = {14,23,423,4,2,3,21,3}; 20 | for (int i = 0; i < array.length; i++) { 21 | System.out.print(array[i] + " "); 22 | } 23 | insertSortTest(array); 24 | System.out.println(); 25 | for (int i = 0; i < array.length; i++) { 26 | System.out.print(array[i] + " "); 27 | } 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /InsertSortByBinaryTest.java: -------------------------------------------------------------------------------- 1 | package cn.it.sort; 2 | 3 | public class InsertSortByBinaryTest { 4 | private static int[] insertSortByBinaryTest(int[] num) { 5 | int low, high, middle; 6 | int temp; 7 | for (int i = 1; i < num.length; i++) { 8 | temp = num[i]; 9 | low = 0; 10 | high = i - 1; 11 | while(low <= high){ 12 | middle = (low + high)>>2; 13 | if (num[middle] > temp) { 14 | high = middle - 1; 15 | } 16 | else{ 17 | low = middle + 1; 18 | } 19 | } 20 | for (int j = i - 1; j > high + 1; j--) { 21 | num[j + 1] = num[j]; 22 | } 23 | num[high + 1] = temp; 24 | } 25 | return num; 26 | } 27 | public static void main(String[] args) { 28 | int array[] = {14,23,423,4,2,3,21,3}; 29 | for (int i = 0; i < array.length; i++) { 30 | System.out.print(array[i] + " "); 31 | } 32 | insertSortByBinaryTest(array); 33 | System.out.println(); 34 | for (int i = 0; i < array.length; i++) { 35 | System.out.print(array[i] + " "); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /ShowPro.java: -------------------------------------------------------------------------------- 1 | package cn.it.sort; 2 | 3 | import javax.swing.plaf.synth.SynthSpinnerUI; 4 | 5 | public class ShowPro { 6 | /** 7 | * @param args 8 | */ 9 | 10 | public static void main(String[] args) { 11 | /* System.out.println(); 12 | System.getProperties().list(System.out); 13 | System.out.println(System.getProperty("user.name")); 14 | System.out.println(System.getProperty("java.library.path"));*/ 15 | int i = 0; 16 | 17 | for (; true; ) { 18 | for (; i < 10; i++) { 19 | System.out.println("i = "+ i); 20 | 21 | if (i == 2) { 22 | System.out.println("continue"); 23 | continue; 24 | } 25 | if (i == 3) { 26 | System.out.println("break"); 27 | i++; 28 | break; 29 | } 30 | if (i == 7) { 31 | System.out.println("continue outer"); 32 | i++; 33 | } 34 | if (i == 8) { 35 | System.out.println("break outer"); 36 | } 37 | for (int k = 0; k < 5; k++) { 38 | if (k == 3) { 39 | System.out.println("continue inner111"); 40 | } 41 | } 42 | } 43 | } 44 | 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /QickSortTest.java: -------------------------------------------------------------------------------- 1 | package cn.it.sort; 2 | 3 | import javax.print.attribute.standard.MediaName; 4 | 5 | public class QickSortTest { 6 | public static void qicksort(int []numbers,int left,int right) { 7 | int temp; 8 | int i = left,j =right; 9 | if (i < j) { 10 | temp = numbers[left]; 11 | while(i != j){ 12 | while(i < j && temp < numbers[j]){ 13 | j--; 14 | } 15 | if (i < j) { 16 | numbers[i] = numbers[j]; 17 | i++; 18 | } 19 | while(i < j && temp > numbers[i]){ 20 | i++; 21 | } 22 | if (i < j) { 23 | numbers[j] = numbers[i]; 24 | j--; 25 | } 26 | } 27 | numbers[i] = temp; 28 | qicksort(numbers, left, i - 1); 29 | qicksort(numbers, i + 1,right); 30 | } 31 | } 32 | public static void main(String[] args) { 33 | int [] numbers ={2,33,4,1,2,3,4}; 34 | for (int i = 0; i < numbers.length; i++) { 35 | System.out.print(numbers[i] + " "); 36 | } 37 | System.out.println(); 38 | qicksort(numbers, 0, numbers.length - 1); 39 | for (int i = 0; i < numbers.length; i++) { 40 | System.out.print(numbers[i] + " "); 41 | } 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /InsertHillSort.java: -------------------------------------------------------------------------------- 1 | package cn.it.sort; 2 | 3 | import java.util.Arrays; 4 | 5 | public class InsertHillSort { 6 | public static void hillsort(int data[]){ 7 | int j = 0; 8 | int temp = 0; 9 | for (int increment = data.length / 2; increment > 0; increment /= 2) { 10 | System.out.println("increment:" + increment); 11 | for (int i = increment; i < data.length; i++) { 12 | // System.out.println("i:" + i); 13 | temp = data[i]; 14 | for (j = i - increment; j >= 0; j -= increment) { 15 | // System.out.println("j:" + j); 16 | // System.out.println("temp:" + temp); 17 | // System.out.println("data[" + j + "]:" + data[j]); 18 | if (temp < data[j]) { 19 | data[j + increment] = data[j]; 20 | } else { 21 | break; 22 | } 23 | } 24 | data[j + increment] = temp; 25 | } 26 | 27 | } 28 | } 29 | 30 | public static void main(String[] args) { 31 | int[] data = new int[] { 26, 53, 67, 48, 57, 13, 48, 32, 60, 50 }; 32 | for (int i = 0; i < data.length; i++) { 33 | System.out.print(data[i] + " "); 34 | } 35 | System.out.println(); 36 | hillsort(data); 37 | 38 | //System.out.println(Arrays.toString(data)); 39 | for (int i = 0; i < data.length; i++) { 40 | System.out.print(data[i] + " "); 41 | } 42 | } 43 | } 44 | --------------------------------------------------------------------------------