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

@ -31,11 +31,11 @@ func insert(nums: inout [Int], num: Int, index: Int) {
for i in nums.indices.dropFirst(index).reversed() {
nums[i] = nums[i - 1]
}
// num index
// num index
nums[index] = num
}
/* index */
/* index */
func remove(nums: inout [Int], index: Int) {
// index
for i in nums.indices.dropFirst(index).dropLast() {

View File

@ -62,7 +62,7 @@ enum LinkedList {
let n2 = ListNode(x: 2)
let n3 = ListNode(x: 5)
let n4 = ListNode(x: 4)
//
//
n0.next = n1
n1.next = n2
n2.next = n3

View File

@ -24,7 +24,7 @@ enum List {
nums.removeAll()
print("清空列表后 nums = \(nums)")
/* */
/* */
nums.append(1)
nums.append(3)
nums.append(2)
@ -32,7 +32,7 @@ enum List {
nums.append(4)
print("添加元素后 nums = \(nums)")
/* */
/* */
nums.insert(6, at: 3)
print("在索引 3 处插入数字 6 ,得到 nums = \(nums)")

View File

@ -4,11 +4,11 @@
* Author: nuomi1 (nuomi1@qq.com)
*/
/* */
/* */
class MyList {
private var arr: [Int] //
private var _capacity = 10 //
private var _size = 0 //
private var _size = 0 //
private let extendRatio = 2 //
/* */
@ -16,7 +16,7 @@ class MyList {
arr = Array(repeating: 0, count: _capacity)
}
/* */
/* */
func size() -> Int {
_size
}
@ -43,7 +43,7 @@ class MyList {
arr[index] = num
}
/* */
/* */
func add(num: Int) {
//
if _size == _capacity {
@ -54,7 +54,7 @@ class MyList {
_size += 1
}
/* */
/* */
func insert(index: Int, num: Int) {
if index < 0 || index >= _size {
fatalError("索引越界")
@ -113,7 +113,7 @@ enum _MyList {
static func main() {
/* */
let nums = MyList()
/* */
/* */
nums.add(num: 1)
nums.add(num: 3)
nums.add(num: 2)
@ -121,7 +121,7 @@ enum _MyList {
nums.add(num: 4)
print("列表 nums = \(nums.toArray()) ,容量 = \(nums.capacity()) ,长度 = \(nums.size())")
/* */
/* */
nums.insert(index: 3, num: 6)
print("在索引 3 处插入数字 6 ,得到 nums = \(nums.toArray())")