Skip to content
New issue

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

Bug fixes and improvements #1133

Merged
merged 3 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions codes/c/chapter_sorting/insertion_sort.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

/* 插入排序 */
void insertionSort(int nums[], int size) {
// 外循环:已排序元素数量为 1, 2, ..., n
// 外循环:已排序区间为 [0, i-1]
for (int i = 1; i < size; i++) {
int base = nums[i], j = i - 1;
// 内循环:将 base 插入到已排序部分的正确位置
// 内循环:将 base 插入到已排序区间 [0, i-1] 中的正确位置
while (j >= 0 && nums[j] > base) {
// 将 nums[j] 向右移动一位
nums[j + 1] = nums[j];
Expand Down
4 changes: 2 additions & 2 deletions codes/cpp/chapter_sorting/insertion_sort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

/* 插入排序 */
void insertionSort(vector<int> &nums) {
// 外循环:已排序元素数量为 1, 2, ..., n
// 外循环:已排序区间为 [0, i-1]
for (int i = 1; i < nums.size(); i++) {
int base = nums[i], j = i - 1;
// 内循环:将 base 插入到已排序部分的正确位置
// 内循环:将 base 插入到已排序区间 [0, i-1] 中的正确位置
while (j >= 0 && nums[j] > base) {
nums[j + 1] = nums[j]; // 将 nums[j] 向右移动一位
j--;
Expand Down
4 changes: 2 additions & 2 deletions codes/csharp/chapter_sorting/insertion_sort.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ namespace hello_algo.chapter_sorting;
public class insertion_sort {
/* 插入排序 */
void InsertionSort(int[] nums) {
// 外循环:已排序元素数量为 1, 2, ..., n
// 外循环:已排序区间为 [0, i-1]
for (int i = 1; i < nums.Length; i++) {
int bas = nums[i], j = i - 1;
// 内循环:将 base 插入到已排序部分的正确位置
// 内循环:将 base 插入到已排序区间 [0, i-1] 中的正确位置
while (j >= 0 && nums[j] > bas) {
nums[j + 1] = nums[j]; // 将 nums[j] 向右移动一位
j--;
Expand Down
4 changes: 2 additions & 2 deletions codes/dart/chapter_sorting/insertion_sort.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

/* 插入排序 */
void insertionSort(List<int> nums) {
// 外循环:已排序元素数量为 1, 2, ..., n
// 外循环:已排序区间为 [0, i-1]
for (int i = 1; i < nums.length; i++) {
int base = nums[i], j = i - 1;
// 内循环:将 base 插入到已排序部分的正确位置
// 内循环:将 base 插入到已排序区间 [0, i-1] 中的正确位置
while (j >= 0 && nums[j] > base) {
nums[j + 1] = nums[j]; // 将 nums[j] 向右移动一位
j--;
Expand Down
2 changes: 1 addition & 1 deletion codes/go/chapter_sorting/insertion_sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ func insertionSort(nums []int) {
for i := 1; i < len(nums); i++ {
base := nums[i]
j := i - 1
// 内循环:将 base 插入到已排序部分的正确位置
// 内循环:将 base 插入到已排序区间 [0, i-1] 中的正确位置
for j >= 0 && nums[j] > base {
nums[j+1] = nums[j] // 将 nums[j] 向右移动一位
j--
Expand Down
4 changes: 2 additions & 2 deletions codes/java/chapter_sorting/insertion_sort.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
public class insertion_sort {
/* 插入排序 */
static void insertionSort(int[] nums) {
// 外循环:已排序元素数量为 1, 2, ..., n
// 外循环:已排序区间为 [0, i-1]
for (int i = 1; i < nums.length; i++) {
int base = nums[i], j = i - 1;
// 内循环:将 base 插入到已排序部分的正确位置
// 内循环:将 base 插入到已排序区间 [0, i-1] 中的正确位置
while (j >= 0 && nums[j] > base) {
nums[j + 1] = nums[j]; // 将 nums[j] 向右移动一位
j--;
Expand Down
4 changes: 2 additions & 2 deletions codes/javascript/chapter_sorting/insertion_sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

/* 插入排序 */
function insertionSort(nums) {
// 外循环:已排序元素数量为 1, 2, ..., n
// 外循环:已排序区间为 [0, i-1]
for (let i = 1; i < nums.length; i++) {
let base = nums[i],
j = i - 1;
// 内循环:将 base 插入到已排序部分的正确位置
// 内循环:将 base 插入到已排序区间 [0, i-1] 中的正确位置
while (j >= 0 && nums[j] > base) {
nums[j + 1] = nums[j]; // 将 nums[j] 向右移动一位
j--;
Expand Down
4 changes: 2 additions & 2 deletions codes/rust/chapter_sorting/insertion_sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ include!("../include/include.rs");

/* 插入排序 */
fn insertion_sort(nums: &mut [i32]) {
// 外循环:已排序元素数量为 1, 2, ..., n
// 外循环:已排序区间为 [0, i-1]
for i in 1..nums.len() {
let (base, mut j) = (nums[i], (i - 1) as i32);
// 内循环:将 base 插入到已排序部分的正确位置
// 内循环:将 base 插入到已排序区间 [0, i-1] 中的正确位置
while j >= 0 && nums[j as usize] > base {
nums[(j + 1) as usize] = nums[j as usize]; // 将 nums[j] 向右移动一位
j -= 1;
Expand Down
4 changes: 2 additions & 2 deletions codes/swift/chapter_sorting/insertion_sort.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

/* 插入排序 */
func insertionSort(nums: inout [Int]) {
// 外循环:已排序元素数量为 1, 2, ..., n
// 外循环:已排序区间为 [0, i-1]
for i in stride(from: 1, to: nums.count, by: 1) {
let base = nums[i]
var j = i - 1
// 内循环:将 base 插入到已排序部分的正确位置
// 内循环:将 base 插入到已排序区间 [0, i-1] 中的正确位置
while j >= 0, nums[j] > base {
nums[j + 1] = nums[j] // 将 nums[j] 向右移动一位
j -= 1
Expand Down
4 changes: 2 additions & 2 deletions codes/typescript/chapter_sorting/insertion_sort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

/* 插入排序 */
function insertionSort(nums: number[]): void {
// 外循环:已排序元素数量为 1, 2, ..., n
// 外循环:已排序区间为 [0, i-1]
for (let i = 1; i < nums.length; i++) {
const base = nums[i];
let j = i - 1;
// 内循环:将 base 插入到已排序部分的正确位置
// 内循环:将 base 插入到已排序区间 [0, i-1] 中的正确位置
while (j >= 0 && nums[j] > base) {
nums[j + 1] = nums[j]; // 将 nums[j] 向右移动一位
j--;
Expand Down
4 changes: 2 additions & 2 deletions codes/zig/chapter_sorting/insertion_sort.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ const inc = @import("include");

// 插入排序
fn insertionSort(nums: []i32) void {
// 外循环:已排序元素数量为 1, 2, ..., n
// 外循环:已排序区间为 [0, i-1]
var i: usize = 1;
while (i < nums.len) : (i += 1) {
var base = nums[i];
var j: usize = i;
// 内循环:将 base 插入到已排序部分的正确位置
// 内循环:将 base 插入到已排序区间 [0, i-1] 中的正确位置
while (j >= 1 and nums[j - 1] > base) : (j -= 1) {
nums[j] = nums[j - 1]; // 将 nums[j] 向右移动一位
}
Expand Down
Binary file modified docs/chapter_paperbook/index.assets/book_jd_link.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/chapter_paperbook/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@ status: new

起初,我低估了纸质书出版的工作量,以为只要维护好了开源项目,纸质版就可以通过某些自动化手段生成出来。实践证明,纸质书的生产流程与开源项目的更新机制存在很大的不同,两者之间的转化需要做许多额外工作。

一本书的初稿与达到出版标准的定稿之间仍有较长距离,需要出版社(策划、编辑、设计、市场等)与作者的通力合作、长期雕琢。在此,在此感谢图灵策划编辑王军花、以及人民邮电出版社和图灵社区每位参与本书出版流程的工作人员!
一本书的初稿与达到出版标准的定稿之间仍有较长距离,需要出版社(策划、编辑、设计、市场等)与作者的通力合作、长期雕琢。在此感谢图灵策划编辑王军花、以及人民邮电出版社和图灵社区每位参与本书出版流程的工作人员!

希望这本书能够帮助到你!
2 changes: 1 addition & 1 deletion docs/chapter_stack_and_queue/queue.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
que.append(4)

# 访问队首元素
front: int = que[0];
front: int = que[0]

# 元素出队
pop: int = que.popleft()
Expand Down
Loading