translation: Capitalize all the headers, list headers and figure captions (#1206)

* Capitalize all the headers, list headers and figure captions

* Fix the term "LRU"

* Fix the names of source code link in avl_tree.md

* Capitalize only first letter for nav trees in mkdocs.yml

* Update code comments

* Update linked_list.md

* Update linked_list.md
This commit is contained in:
Yudong Jin
2024-04-04 17:09:53 +08:00
committed by GitHub
parent 5e2eef0b4d
commit 07f7eb12ff
34 changed files with 376 additions and 376 deletions
+11 -11
View File
@@ -11,9 +11,9 @@ To solve this problem, we can implement lists using a "dynamic array." It inheri
In fact, **many programming languages' standard libraries implement lists using dynamic arrays**, such as Python's `list`, Java's `ArrayList`, C++'s `vector`, and C#'s `List`. In the following discussion, we will consider "list" and "dynamic array" as synonymous concepts.
## Common List Operations
## Common list operations
### Initializing a List
### Initializing a list
We typically use two initialization methods: "without initial values" and "with initial values".
@@ -141,7 +141,7 @@ We typically use two initialization methods: "without initial values" and "with
try nums.appendSlice(&[_]i32{ 1, 3, 2, 5, 4 });
```
### Accessing Elements
### Accessing elements
Lists are essentially arrays, thus they can access and update elements in $O(1)$ time, which is very efficient.
@@ -266,7 +266,7 @@ Lists are essentially arrays, thus they can access and update elements in $O(1)$
nums.items[1] = 0; // Update the element at index 1 to 0
```
### Inserting and Removing Elements
### Inserting and removing elements
Compared to arrays, lists offer more flexibility in adding and removing elements. While adding elements to the end of a list is an $O(1)$ operation, the efficiency of inserting and removing elements elsewhere in the list remains the same as in arrays, with a time complexity of $O(n)$.
@@ -502,7 +502,7 @@ Compared to arrays, lists offer more flexibility in adding and removing elements
_ = nums.orderedRemove(3); // Remove the element at index 3
```
### Iterating the List
### Iterating the list
Similar to arrays, lists can be iterated either by using indices or by directly iterating through each element.
@@ -691,7 +691,7 @@ Similar to arrays, lists can be iterated either by using indices or by directly
}
```
### Concatenating Lists
### Concatenating lists
Given a new list `nums1`, we can append it to the end of the original list.
@@ -798,7 +798,7 @@ Given a new list `nums1`, we can append it to the end of the original list.
try nums.insertSlice(nums.items.len, nums1.items); // Concatenate nums1 to the end of nums
```
### Sorting the List
### Sorting the list
Once the list is sorted, we can employ algorithms commonly used in array-related algorithm problems, such as "binary search" and "two-pointer" algorithms.
@@ -891,15 +891,15 @@ Once the list is sorted, we can employ algorithms commonly used in array-related
std.sort.sort(i32, nums.items, {}, comptime std.sort.asc(i32));
```
## List Implementation
## List implementation
Many programming languages come with built-in lists, including Java, C++, Python, etc. Their implementations tend to be intricate, featuring carefully considered settings for various parameters, like initial capacity and expansion factors. Readers who are curious can delve into the source code for further learning.
To enhance our understanding of how lists work, we will attempt to implement a simplified version of a list, focusing on three crucial design aspects:
- **Initial Capacity**: Choose a reasonable initial capacity for the array. In this example, we choose 10 as the initial capacity.
- **Size Recording**: Declare a variable `size` to record the current number of elements in the list, updating in real-time with element insertion and deletion. With this variable, we can locate the end of the list and determine whether expansion is needed.
- **Expansion Mechanism**: If the list reaches full capacity upon an element insertion, an expansion process is required. This involves creating a larger array based on the expansion factor, and then transferring all elements from the current array to the new one. In this example, we stipulate that the array size should double with each expansion.
- **Initial capacity**: Choose a reasonable initial capacity for the array. In this example, we choose 10 as the initial capacity.
- **Size recording**: Declare a variable `size` to record the current number of elements in the list, updating in real-time with element insertion and deletion. With this variable, we can locate the end of the list and determine whether expansion is needed.
- **Expansion mechanism**: If the list reaches full capacity upon an element insertion, an expansion process is required. This involves creating a larger array based on the expansion factor, and then transferring all elements from the current array to the new one. In this example, we stipulate that the array size should double with each expansion.
```src
[file]{my_list}-[class]{my_list}-[func]{}