Several bug fixes and improvements (#945)

* Update Dockerfile for code debugging.

* Format Python code using Black.

* Improve dark theme by defining html classes for the figures, animations and cover images.

* Fix several glossary translation.

* Update a code comment.

* Fix climbing_stairs_backtrack: the pruning should not require the sorted choices list.

* Update the code of array and list traversal.

* Fix a rendering issue of README.md

* Update code of list traversal.

* Fix array_definition.png

* Update README.md

* Fix max_capacity_moving_short_board.png

* Fix array.dart

* Fix array.dart

* Fix array.dart

* Fix array.dart
This commit is contained in:
Yudong Jin
2023-11-14 21:27:35 +08:00
committed by GitHub
parent 9baf4a1753
commit fcbaf101a4
64 changed files with 212 additions and 218 deletions

View File

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 21 KiB

View File

@@ -1,10 +1,6 @@
# 数组与链表
<div class="center-table" markdown>
![数组与链表](../assets/covers/chapter_array_and_linkedlist.jpg){ width="600" }
</div>
![数组与链表](../assets/covers/chapter_array_and_linkedlist.jpg)
!!! abstract

View File

@@ -494,12 +494,11 @@
# 通过索引遍历列表
count = 0
for i in range(len(nums)):
count += 1
count += nums[i]
# 直接遍历列表元素
count = 0
for num in nums:
count += 1
count += num
```
=== "C++"
@@ -508,13 +507,13 @@
/* 通过索引遍历列表 */
int count = 0;
for (int i = 0; i < nums.size(); i++) {
count++;
count += nums[i];
}
/* 直接遍历列表元素 */
count = 0;
for (int num : nums) {
count++;
count += num;
}
```
@@ -524,13 +523,12 @@
/* 通过索引遍历列表 */
int count = 0;
for (int i = 0; i < nums.size(); i++) {
count++;
count += nums.get(i);
}
/* 直接遍历列表元素 */
count = 0;
for (int num : nums) {
count++;
count += num;
}
```
@@ -540,13 +538,13 @@
/* 通过索引遍历列表 */
int count = 0;
for (int i = 0; i < nums.Count; i++) {
count++;
count += nums[i];
}
/* 直接遍历列表元素 */
count = 0;
foreach (int num in nums) {
count++;
count += num;
}
```
@@ -556,13 +554,13 @@
/* 通过索引遍历列表 */
count := 0
for i := 0; i < len(nums); i++ {
count++
count += nums[i]
}
/* 直接遍历列表元素 */
count = 0
for range nums {
count++
for _, num := range nums {
count += num
}
```
@@ -571,14 +569,14 @@
```swift title="list.swift"
/* 通过索引遍历列表 */
var count = 0
for _ in nums.indices {
count += 1
for i in nums.indices {
count += nums[i]
}
/* 直接遍历列表元素 */
count = 0
for _ in nums {
count += 1
for num in nums {
count += num
}
```
@@ -588,13 +586,13 @@
/* 通过索引遍历列表 */
let count = 0;
for (let i = 0; i < nums.length; i++) {
count++;
count += nums[i];
}
/* 直接遍历列表元素 */
count = 0;
for (const num of nums) {
count++;
count += num;
}
```
@@ -604,13 +602,13 @@
/* 通过索引遍历列表 */
let count = 0;
for (let i = 0; i < nums.length; i++) {
count++;
count += nums[i];
}
/* 直接遍历列表元素 */
count = 0;
for (const num of nums) {
count++;
count += num;
}
```
@@ -619,30 +617,30 @@
```dart title="list.dart"
/* 通过索引遍历列表 */
int count = 0;
for (int i = 0; i < nums.length; i++) {
count++;
for (var i = 0; i < nums.length; i++) {
count += nums[i];
}
/* 直接遍历列表元素 */
count = 0;
for (int num in nums) {
count++;
for (var num in nums) {
count += num;
}
```
=== "Rust"
```rust title="list.rs"
/* 通过索引遍历列表 */
let mut count = 0;
for (index, value) in nums.iter().enumerate() {
count += 1;
// 通过索引遍历列表
let mut _count = 0;
for i in 0..nums.len() {
_count += nums[i];
}
/* 直接遍历列表元素 */
let mut count = 0;
for value in nums.iter() {
count += 1;
// 直接遍历列表元素
_count = 0;
for num in &nums {
_count += num;
}
```
@@ -659,13 +657,13 @@
var count: i32 = 0;
var i: i32 = 0;
while (i < nums.items.len) : (i += 1) {
count += 1;
count += nums[i];
}
// 直接遍历列表元素
count = 0;
for (nums.items) |_| {
count += 1;
for (nums.items) |num| {
count += num;
}
```

View File

@@ -33,7 +33,7 @@
不修改 `P.next` 也可以。从该链表的角度看,从头节点遍历到尾节点已经遇不到 `P` 了。这意味着节点 `P` 已经从链表中删除了,此时节点 `P` 指向哪里都不会对这条链表产生影响了。
从垃圾回收的角度看,对于 Java、Python、Go 等拥有自动垃圾回收的语言来说,节点 `P` 是否被回收取决于是否仍存在指向它的引用,而不是 `P.next` 的值。在 C 和 C++ 等语言中,我们需要手动释放节点内存。
从垃圾回收的角度看,对于 Java、Python、Go 等拥有自动垃圾回收的语言来说,节点 `P` 是否被回收取决于是否仍存在指向它的引用,而不是 `P.next` 的值。在 C 和 C++ 等语言中,我们需要手动释放节点内存。
!!! question "在链表中插入和删除操作的时间复杂度是 $O(1)$ 。但是增删之前都需要 $O(n)$ 查找元素,那为什么时间复杂度不是 $O(n)$ 呢?"