diff --git a/src/dataANDcalc/java/SortAlgori/InsertSort.java b/src/dataANDcalc/java/SortAlgori/InsertSort.java new file mode 100644 index 0000000..0182597 --- /dev/null +++ b/src/dataANDcalc/java/SortAlgori/InsertSort.java @@ -0,0 +1,106 @@ +package SortAlgori; + +public class InsertSort { + + private int[] arr; + + private int[] sort; + + private SortNode head = new SortNode(); + + public InsertSort(int[] arr){ + this.arr = arr; + this.sort = new int[arr.length]; + this.sort[0] = arr[0]; + + head.next = new SortNode(arr[0]); + } + + private void sort(){ + for (int i = 1; i =0 && temp < sort[index]){ + sort[index+1] = sort[index]; + index --; + } + //将当前数插入到下标+1的位置 + sort[index+1] = temp; + } + } + + private void sortByLinkedList(){ + for(int i=1; i