feat: Revised the book (#978)

* Sync recent changes to the revised Word.

* Revised the preface chapter

* Revised the introduction chapter

* Revised the computation complexity chapter

* Revised the chapter data structure

* Revised the chapter array and linked list

* Revised the chapter stack and queue

* Revised the chapter hashing

* Revised the chapter tree

* Revised the chapter heap

* Revised the chapter graph

* Revised the chapter searching

* Reivised the sorting chapter

* Revised the divide and conquer chapter

* Revised the chapter backtacking

* Revised the DP chapter

* Revised the greedy chapter

* Revised the appendix chapter

* Revised the preface chapter doubly

* Revised the figures
This commit is contained in:
Yudong Jin
2023-12-02 06:21:34 +08:00
committed by GitHub
parent b824d149cb
commit e720aa2d24
404 changed files with 1537 additions and 1558 deletions

View File

@@ -12,7 +12,7 @@ void bucketSort(List<double> nums) {
// 1. 将数组元素分配到各个桶中
for (double _num in nums) {
// 输入数据范围 [0, 1),使用 _num * k 映射到索引范围 [0, k-1]
// 输入数据范围 [0, 1),使用 _num * k 映射到索引范围 [0, k-1]
int i = (_num * k).toInt();
// 将 _num 添加进桶 bucket_idx
buckets[i].add(_num);

View File

@@ -32,7 +32,7 @@ void heapSort(List<int> nums) {
}
// 从堆中提取最大元素,循环 n-1 轮
for (int i = nums.length - 1; i > 0; i--) {
// 交换根节点与最右叶节点(交换首元素与尾元素)
// 交换根节点与最右叶节点(交换首元素与尾元素)
int tmp = nums[0];
nums[0] = nums[i];
nums[i] = tmp;

View File

@@ -15,7 +15,7 @@ class QuickSort {
/* 哨兵划分 */
static int _partition(List<int> nums, int left, int right) {
// 以 nums[left] 为基准数
// 以 nums[left] 为基准数
int i = left, j = right;
while (i < j) {
while (i < j && nums[j] >= nums[left]) j--; // 从右向左找首个小于基准数的元素
@@ -65,7 +65,7 @@ class QuickSortMedian {
int med = _medianThree(nums, left, (left + right) ~/ 2, right);
// 将中位数交换至数组最左端
_swap(nums, left, med);
// 以 nums[left] 为基准数
// 以 nums[left] 为基准数
int i = left, j = right;
while (i < j) {
while (i < j && nums[j] >= nums[left]) j--; // 从右向左找首个小于基准数的元素
@@ -99,7 +99,7 @@ class QuickSortTailCall {
/* 哨兵划分 */
static int _partition(List<int> nums, int left, int right) {
// 以 nums[left] 为基准数
// 以 nums[left] 为基准数
int i = left, j = right;
while (i < j) {
while (i < j && nums[j] >= nums[left]) j--; // 从右向左找首个小于基准数的元素
@@ -116,7 +116,7 @@ class QuickSortTailCall {
while (left < right) {
// 哨兵划分操作
int pivot = _partition(nums, left, right);
// 对两个子数组中较短的那个执行快
// 对两个子数组中较短的那个执行快速排序
if (pivot - left < right - pivot) {
quickSort(nums, left, pivot - 1); // 递归排序左子数组
left = pivot + 1; // 剩余未排序区间为 [pivot + 1, right]

View File

@@ -12,7 +12,7 @@ int digit(int _num, int exp) {
/* 计数排序(根据 nums 第 k 位排序) */
void countingSortDigit(List<int> nums, int exp) {
// 十进制的位范围为 0~9 ,因此需要长度为 10 的桶
// 十进制的位范围为 0~9 ,因此需要长度为 10 的桶数组
List<int> counter = List<int>.filled(10, 0);
int n = nums.length;
// 统计 0~9 各数字的出现次数