Skip to content

Commit bf5b15c

Browse files
committed
* 'master' of https://github.com/frank-lam/2019_campus_appy: 修改插入排序算法 bug
2 parents ec7cfd1 + 565758a commit bf5b15c

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

‎notes/数据结构与算法.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ private static void swap(int[] arr, int i, int j) {
134134

135135
```java
136136
public static void sort(int[] arr) {
137-
for (int i = 0; i < arr.length; i++) {
138-
for (int j = i + 1; j >= 0; j--) {
137+
for (int i = 0; i < arr.length - 1; i++) {
138+
for (int j = i + 1; j > 0; j--) {
139139
if (arr[j] < arr[j - 1])
140140
swap(arr, j, j - 1); // 大量的交换会消耗时间
141141
else

0 commit comments

Comments
 (0)