From b1758784c70122a4eb1a1743f6f50a329580e132 Mon Sep 17 00:00:00 2001 From: liangjinglin Date: Thu, 16 Jan 2025 15:44:10 +0800 Subject: [PATCH] =?UTF-8?q?2025-01-16=20=E6=8F=92=E5=85=A5=E6=8E=92?= =?UTF-8?q?=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/SortAlgori/InsertSort.java | 106 ++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 src/dataANDcalc/java/SortAlgori/InsertSort.java 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