We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
“j”的取值范围应该 “j>=0” public void insertSort(int[] arr) { int len = arr.length; //要插入的数 int insertNum; //因为第一次不用,所以从1开始 for (int i = 1; i < len; i++) { insertNum = arr[i]; //序列元素个数 int j = i - 1; //从后往前循环,将大于insertNum的数向后移动 while (j >= 0 && arr[j] > insertNum) { //元素向后移动 arr[j + 1] = arr[j]; j--; } //找到位置,插入当前元素 arr[j + 1] = insertNum; } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
“j”的取值范围应该 “j>=0”
public void insertSort(int[] arr) {
int len = arr.length;
//要插入的数
int insertNum;
//因为第一次不用,所以从1开始
for (int i = 1; i < len; i++) {
insertNum = arr[i];
//序列元素个数
int j = i - 1;
//从后往前循环,将大于insertNum的数向后移动
while (j >= 0 && arr[j] > insertNum) {
//元素向后移动
arr[j + 1] = arr[j];
j--;
}
//找到位置,插入当前元素
arr[j + 1] = insertNum;
}
}
The text was updated successfully, but these errors were encountered: