From 311f084ee6dda6db7a47247470c128aaf41e705e Mon Sep 17 00:00:00 2001 From: 30980 <309804010@qq.com> Date: Wed, 24 Aug 2022 21:57:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=92=E5=85=A5=E6=8E=92=E5=BA=8Fdemo1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/never/basic/InsertSort.java | 18 ++++++++++++++++++ src/main/java/com/never/basic/SortDemo.java | 3 ++- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/never/basic/InsertSort.java diff --git a/src/main/java/com/never/basic/InsertSort.java b/src/main/java/com/never/basic/InsertSort.java new file mode 100644 index 0000000..8b6ef9f --- /dev/null +++ b/src/main/java/com/never/basic/InsertSort.java @@ -0,0 +1,18 @@ +package com.never.basic; + +public class InsertSort { + public void insertSort(int[] arr){ + if(arr == null ||arr.length<2){ + return; + } + int minIndex = 0; + for(int end = 1; end < arr.length; end ++){ + minIndex = end; + + while(minIndex>0 && arr[minIndex]