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

@ -37,11 +37,11 @@ public class array {
for (int i = nums.length - 1; i > index; i--) {
nums[i] = nums[i - 1];
}
// 将 num 赋给 index 处元素
// 将 num 赋给 index 处元素
nums[index] = num;
}
/* 删除索引 index 处元素 */
/* 删除索引 index 处元素 */
static void remove(int[] nums, int index) {
// 把索引 index 之后的所有元素向前移动一位
for (int i = index; i < nums.length - 1; i++) {

View File

@ -57,7 +57,7 @@ public class linked_list {
ListNode n2 = new ListNode(2);
ListNode n3 = new ListNode(5);
ListNode n4 = new ListNode(4);
// 构建引用指向
// 构建节点之间的引用
n0.next = n1;
n1.next = n2;
n2.next = n3;

View File

@ -28,7 +28,7 @@ public class list {
nums.clear();
System.out.println("清空列表后 nums = " + nums);
/* 尾部添加元素 */
/* 尾部添加元素 */
nums.add(1);
nums.add(3);
nums.add(2);
@ -36,7 +36,7 @@ public class list {
nums.add(4);
System.out.println("添加元素后 nums = " + nums);
/* 中间插入元素 */
/* 中间插入元素 */
nums.add(3, 6);
System.out.println("在索引 3 处插入数字 6 ,得到 nums = " + nums);

View File

@ -8,11 +8,11 @@ package chapter_array_and_linkedlist;
import java.util.*;
/* 列表类简易实现 */
/* 列表类 */
class MyList {
private int[] arr; // 数组(存储列表元素)
private int capacity = 10; // 列表容量
private int size = 0; // 列表长度(当前元素数量)
private int size = 0; // 列表长度(当前元素数量)
private int extendRatio = 2; // 每次列表扩容的倍数
/* 构造方法 */
@ -20,7 +20,7 @@ class MyList {
arr = new int[capacity];
}
/* 获取列表长度(当前元素数量) */
/* 获取列表长度(当前元素数量) */
public int size() {
return size;
}
@ -45,7 +45,7 @@ class MyList {
arr[index] = num;
}
/* 尾部添加元素 */
/* 尾部添加元素 */
public void add(int num) {
// 元素数量超出容量时,触发扩容机制
if (size == capacity())
@ -55,7 +55,7 @@ class MyList {
size++;
}
/* 中间插入元素 */
/* 中间插入元素 */
public void insert(int index, int num) {
if (index < 0 || index >= size)
throw new IndexOutOfBoundsException("索引越界");
@ -111,7 +111,7 @@ public class my_list {
public static void main(String[] args) {
/* 初始化列表 */
MyList nums = new MyList();
/* 尾部添加元素 */
/* 尾部添加元素 */
nums.add(1);
nums.add(3);
nums.add(2);
@ -120,7 +120,7 @@ public class my_list {
System.out.println("列表 nums = " + Arrays.toString(nums.toArray()) +
" ,容量 = " + nums.capacity() + " ,长度 = " + nums.size());
/* 中间插入元素 */
/* 中间插入元素 */
nums.insert(3, 6);
System.out.println("在索引 3 处插入数字 6 ,得到 nums = " + Arrays.toString(nums.toArray()));