mirror of
				https://github.com/krahets/hello-algo.git
				synced 2025-11-04 06:07:20 +08:00 
			
		
		
		
	Merge branch 'krahets:master' into master
This commit is contained in:
		
							
								
								
									
										123
									
								
								codes/go/chapter_computational_complexity/space_complexity.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										123
									
								
								codes/go/chapter_computational_complexity/space_complexity.go
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,123 @@
 | 
				
			|||||||
 | 
					// File: space_complexity.go
 | 
				
			||||||
 | 
					// Created Time: 2022-12-15
 | 
				
			||||||
 | 
					// Author: cathay (cathaycchen@gmail.com)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					package chapter_computational_complexity
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"strconv"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Node 结构体 */
 | 
				
			||||||
 | 
					type Node struct {
 | 
				
			||||||
 | 
						val  int
 | 
				
			||||||
 | 
						next *Node
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* TreeNode 二叉树 */
 | 
				
			||||||
 | 
					type TreeNode struct {
 | 
				
			||||||
 | 
						val   int
 | 
				
			||||||
 | 
						left  *TreeNode
 | 
				
			||||||
 | 
						right *TreeNode
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* 创建 Node 结构体  */
 | 
				
			||||||
 | 
					func newNode(val int) *Node {
 | 
				
			||||||
 | 
						return &Node{val: val}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* 创建 TreeNode 结构体 */
 | 
				
			||||||
 | 
					func newTreeNode(val int) *TreeNode {
 | 
				
			||||||
 | 
						return &TreeNode{val: val}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* 输出二叉树 */
 | 
				
			||||||
 | 
					func printTree(root *TreeNode) {
 | 
				
			||||||
 | 
						if root == nil {
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						fmt.Println(root.val)
 | 
				
			||||||
 | 
						printTree(root.left)
 | 
				
			||||||
 | 
						printTree(root.right)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* 函数(或称方法)*/
 | 
				
			||||||
 | 
					func function() int {
 | 
				
			||||||
 | 
						// do something...
 | 
				
			||||||
 | 
						return 0
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* 常数阶 */
 | 
				
			||||||
 | 
					func spaceConstant(n int) {
 | 
				
			||||||
 | 
						// 常量、变量、对象占用 O(1) 空间
 | 
				
			||||||
 | 
						const a = 0
 | 
				
			||||||
 | 
						b := 0
 | 
				
			||||||
 | 
						nums := make([]int, 10000)
 | 
				
			||||||
 | 
						ListNode := newNode(0)
 | 
				
			||||||
 | 
						// 循环中的变量占用 O(1) 空间
 | 
				
			||||||
 | 
						var c int
 | 
				
			||||||
 | 
						for i := 0; i < n; i++ {
 | 
				
			||||||
 | 
							c = 0
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						// 循环中的函数占用 O(1) 空间
 | 
				
			||||||
 | 
						for i := 0; i < n; i++ {
 | 
				
			||||||
 | 
							function()
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						fmt.Println(a, b, nums, c, ListNode)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* 线性阶 */
 | 
				
			||||||
 | 
					func spaceLinear(n int) {
 | 
				
			||||||
 | 
						// 长度为 n 的数组占用 O(n) 空间
 | 
				
			||||||
 | 
						_ = make([]int, n)
 | 
				
			||||||
 | 
						// 长度为 n 的列表占用 O(n) 空间
 | 
				
			||||||
 | 
						var nodes []*Node
 | 
				
			||||||
 | 
						for i := 0; i < n; i++ {
 | 
				
			||||||
 | 
							nodes = append(nodes, newNode(i))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						// 长度为 n 的哈希表占用 O(n) 空间
 | 
				
			||||||
 | 
						m := make(map[int]string, n)
 | 
				
			||||||
 | 
						for i := 0; i < n; i++ {
 | 
				
			||||||
 | 
							m[i] = strconv.Itoa(i)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* 线性阶(递归实现) */
 | 
				
			||||||
 | 
					func spaceLinearRecur(n int) {
 | 
				
			||||||
 | 
						fmt.Println("递归 n =", n)
 | 
				
			||||||
 | 
						if n == 1 {
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						spaceLinearRecur(n - 1)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* 平方阶 */
 | 
				
			||||||
 | 
					func spaceQuadratic(n int) {
 | 
				
			||||||
 | 
						// 矩阵占用 O(n^2) 空间
 | 
				
			||||||
 | 
						numMatrix := make([][]int, n)
 | 
				
			||||||
 | 
						for i := 0; i < n; i++ {
 | 
				
			||||||
 | 
							numMatrix[i] = make([]int, n)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* 平方阶(递归实现) */
 | 
				
			||||||
 | 
					func spaceQuadraticRecur(n int) int {
 | 
				
			||||||
 | 
						if n <= 0 {
 | 
				
			||||||
 | 
							return 0
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						nums := make([]int, n)
 | 
				
			||||||
 | 
						fmt.Printf("递归 n = %d 中的 nums 长度 = %d \n", n, len(nums))
 | 
				
			||||||
 | 
						return spaceQuadraticRecur(n - 1)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* 指数阶(建立满二叉树) */
 | 
				
			||||||
 | 
					func buildTree(n int) *TreeNode {
 | 
				
			||||||
 | 
						if n == 0 {
 | 
				
			||||||
 | 
							return nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						root := newTreeNode(0)
 | 
				
			||||||
 | 
						root.left = buildTree(n - 1)
 | 
				
			||||||
 | 
						root.right = buildTree(n - 1)
 | 
				
			||||||
 | 
						return root
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -0,0 +1,30 @@
 | 
				
			|||||||
 | 
					// File: space_complexity_test.go
 | 
				
			||||||
 | 
					// Created Time: 2022-12-15
 | 
				
			||||||
 | 
					// Author: cathay (cathaycchen@gmail.com)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					package chapter_computational_complexity
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"testing"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestSpaceComplexity(t *testing.T) {
 | 
				
			||||||
 | 
						/* ======= Test Case ======= */
 | 
				
			||||||
 | 
						n := 5
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* ====== Driver Code ====== */
 | 
				
			||||||
 | 
						// 常数阶
 | 
				
			||||||
 | 
						spaceConstant(n)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 线性阶
 | 
				
			||||||
 | 
						spaceLinear(n)
 | 
				
			||||||
 | 
						spaceLinearRecur(n)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 平方阶
 | 
				
			||||||
 | 
						spaceQuadratic(n)
 | 
				
			||||||
 | 
						spaceQuadraticRecur(n)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 指数阶
 | 
				
			||||||
 | 
						root := buildTree(n)
 | 
				
			||||||
 | 
						printTree(root)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -52,7 +52,7 @@ class ArrayHashMap {
 | 
				
			|||||||
    /* 删除操作 */
 | 
					    /* 删除操作 */
 | 
				
			||||||
    public void remove(int key) {
 | 
					    public void remove(int key) {
 | 
				
			||||||
        int index = hashFunc(key);
 | 
					        int index = hashFunc(key);
 | 
				
			||||||
        // 置为空字符,代表删除
 | 
					        // 置为 null ,代表删除
 | 
				
			||||||
        bucket.set(index, null);
 | 
					        bucket.set(index, null);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -102,7 +102,30 @@ comments: true
 | 
				
			|||||||
=== "Go"
 | 
					=== "Go"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```go title=""
 | 
					    ```go title=""
 | 
				
			||||||
 | 
					    /* 结构体 */
 | 
				
			||||||
 | 
					    type Node struct {
 | 
				
			||||||
 | 
					        val  int
 | 
				
			||||||
 | 
					        next *Node
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
					    /* 创建 Node 结构体 */
 | 
				
			||||||
 | 
					    func newNode(val int) *Node {
 | 
				
			||||||
 | 
					        return &Node{val: val}
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    /* 函数(或称方法)*/
 | 
				
			||||||
 | 
					    func function() int {
 | 
				
			||||||
 | 
					        // do something...
 | 
				
			||||||
 | 
					        return 0
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    func algorithm(n int) int { // 输入数据
 | 
				
			||||||
 | 
					        const a = 0             // 暂存数据(常量)
 | 
				
			||||||
 | 
					        b := 0                  // 暂存数据(变量)
 | 
				
			||||||
 | 
					        newNode(0)              // 暂存数据(对象)
 | 
				
			||||||
 | 
					        c := function()         // 栈帧空间(调用函数)
 | 
				
			||||||
 | 
					        return a + b + c        // 输出数据
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    ```
 | 
					    ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
=== "JavaScript"
 | 
					=== "JavaScript"
 | 
				
			||||||
@ -173,7 +196,15 @@ comments: true
 | 
				
			|||||||
=== "Go"
 | 
					=== "Go"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```go title=""
 | 
					    ```go title=""
 | 
				
			||||||
 | 
					    func algorithm(n int) {
 | 
				
			||||||
 | 
					        a := 0                         // O(1)
 | 
				
			||||||
 | 
					        b := make([]int, 10000)        // O(1)
 | 
				
			||||||
 | 
					        var nums []int
 | 
				
			||||||
 | 
					        if n > 10 {
 | 
				
			||||||
 | 
					            nums = make([]int, 10000)  // O(n)
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        fmt.Println(a, b, nums)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    ```
 | 
					    ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
=== "JavaScript"
 | 
					=== "JavaScript"
 | 
				
			||||||
@ -263,7 +294,25 @@ comments: true
 | 
				
			|||||||
=== "Go"
 | 
					=== "Go"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```go title=""
 | 
					    ```go title=""
 | 
				
			||||||
 | 
					    func function() int {
 | 
				
			||||||
 | 
					        // do something
 | 
				
			||||||
 | 
					        return 0
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
					    /* 循环 O(1) */
 | 
				
			||||||
 | 
					    func loop(n int) {
 | 
				
			||||||
 | 
					        for i := 0; i < n; i++ {
 | 
				
			||||||
 | 
					            function()
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    /* 递归 O(n) */
 | 
				
			||||||
 | 
					    func recur(n int) {
 | 
				
			||||||
 | 
					        if n == 1 {
 | 
				
			||||||
 | 
					            return
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        recur(n - 1)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    ```
 | 
					    ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
=== "JavaScript"
 | 
					=== "JavaScript"
 | 
				
			||||||
@ -377,7 +426,24 @@ $$
 | 
				
			|||||||
=== "Go"
 | 
					=== "Go"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```go title="space_complexity.go"
 | 
					    ```go title="space_complexity.go"
 | 
				
			||||||
 | 
					    /* 常数阶 */
 | 
				
			||||||
 | 
					    func spaceConstant(n int) {
 | 
				
			||||||
 | 
					        // 常量、变量、对象占用 O(1) 空间
 | 
				
			||||||
 | 
					        const a = 0
 | 
				
			||||||
 | 
					        b := 0
 | 
				
			||||||
 | 
					        nums := make([]int, 10000)
 | 
				
			||||||
 | 
					        ListNode := newNode(0)
 | 
				
			||||||
 | 
					        // 循环中的变量占用 O(1) 空间
 | 
				
			||||||
 | 
					        var c int
 | 
				
			||||||
 | 
					        for i := 0; i < n; i++ {
 | 
				
			||||||
 | 
					            c = 0
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        // 循环中的函数占用 O(1) 空间
 | 
				
			||||||
 | 
					        for i := 0; i < n; i++ {
 | 
				
			||||||
 | 
					            function()
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        fmt.Println(a, b, nums, c, ListNode)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    ```
 | 
					    ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
=== "JavaScript"
 | 
					=== "JavaScript"
 | 
				
			||||||
@ -464,7 +530,21 @@ $$
 | 
				
			|||||||
=== "Go"
 | 
					=== "Go"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```go title="space_complexity.go"
 | 
					    ```go title="space_complexity.go"
 | 
				
			||||||
 | 
					    /* 线性阶 */
 | 
				
			||||||
 | 
					    func spaceLinear(n int) {
 | 
				
			||||||
 | 
					        // 长度为 n 的数组占用 O(n) 空间
 | 
				
			||||||
 | 
					        _ = make([]int, n)
 | 
				
			||||||
 | 
					        // 长度为 n 的列表占用 O(n) 空间
 | 
				
			||||||
 | 
					        var nodes []*Node
 | 
				
			||||||
 | 
					        for i := 0; i < n; i++ {
 | 
				
			||||||
 | 
					            nodes = append(nodes, newNode(i))
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        // 长度为 n 的哈希表占用 O(n) 空间
 | 
				
			||||||
 | 
						    m := make(map[int]string, n)
 | 
				
			||||||
 | 
					        for i := 0; i < n; i++ {
 | 
				
			||||||
 | 
					            m[i] = strconv.Itoa(i)
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    ```
 | 
					    ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
=== "JavaScript"
 | 
					=== "JavaScript"
 | 
				
			||||||
@ -528,7 +608,14 @@ $$
 | 
				
			|||||||
=== "Go"
 | 
					=== "Go"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```go title="space_complexity.go"
 | 
					    ```go title="space_complexity.go"
 | 
				
			||||||
 | 
					    /* 线性阶(递归实现) */
 | 
				
			||||||
 | 
					    func spaceLinearRecur(n int) {
 | 
				
			||||||
 | 
					        fmt.Println("递归 n =", n)
 | 
				
			||||||
 | 
					        if n == 1 {
 | 
				
			||||||
 | 
					            return
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        spaceLinearRecur(n - 1)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    ```
 | 
					    ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
=== "JavaScript"
 | 
					=== "JavaScript"
 | 
				
			||||||
@ -611,7 +698,14 @@ $$
 | 
				
			|||||||
=== "Go"
 | 
					=== "Go"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```go title="space_complexity.go"
 | 
					    ```go title="space_complexity.go"
 | 
				
			||||||
 | 
					    /* 平方阶 */
 | 
				
			||||||
 | 
					    func spaceQuadratic(n int) {
 | 
				
			||||||
 | 
					        // 矩阵占用 O(n^2) 空间
 | 
				
			||||||
 | 
					        numMatrix := make([][]int, n)
 | 
				
			||||||
 | 
					        for i := 0; i < n; i++ {
 | 
				
			||||||
 | 
					            numMatrix[i] = make([]int, n)
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    ```
 | 
					    ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
=== "JavaScript"
 | 
					=== "JavaScript"
 | 
				
			||||||
@ -678,7 +772,15 @@ $$
 | 
				
			|||||||
=== "Go"
 | 
					=== "Go"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```go title="space_complexity.go"
 | 
					    ```go title="space_complexity.go"
 | 
				
			||||||
 | 
					    /* 平方阶(递归实现) */
 | 
				
			||||||
 | 
					    func spaceQuadraticRecur(n int) int {
 | 
				
			||||||
 | 
					        if n <= 0 {
 | 
				
			||||||
 | 
					            return 0
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        nums := make([]int, n)
 | 
				
			||||||
 | 
					        fmt.Printf("递归 n = %d 中的 nums 长度 = %d \n", n, len(nums))
 | 
				
			||||||
 | 
					        return spaceQuadraticRecur(n - 1)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    ```
 | 
					    ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
=== "JavaScript"
 | 
					=== "JavaScript"
 | 
				
			||||||
@ -754,7 +856,16 @@ $$
 | 
				
			|||||||
=== "Go"
 | 
					=== "Go"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```go title="space_complexity.go"
 | 
					    ```go title="space_complexity.go"
 | 
				
			||||||
 | 
					    /* 指数阶(建立满二叉树) */
 | 
				
			||||||
 | 
					    func buildTree(n int) *TreeNode {
 | 
				
			||||||
 | 
					        if n == 0 {
 | 
				
			||||||
 | 
					            return nil
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        root := newTreeNode(0)
 | 
				
			||||||
 | 
					        root.left = buildTree(n - 1)
 | 
				
			||||||
 | 
					        root.right = buildTree(n - 1)
 | 
				
			||||||
 | 
					        return root
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    ```
 | 
					    ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
=== "JavaScript"
 | 
					=== "JavaScript"
 | 
				
			||||||
 | 
				
			|||||||
@ -317,7 +317,7 @@ $$
 | 
				
			|||||||
        /* 删除操作 */
 | 
					        /* 删除操作 */
 | 
				
			||||||
        public void remove(int key) {
 | 
					        public void remove(int key) {
 | 
				
			||||||
            int index = hashFunc(key);
 | 
					            int index = hashFunc(key);
 | 
				
			||||||
            // 置为空字符,代表删除
 | 
					            // 置为 null,代表删除
 | 
				
			||||||
            bucket.set(index, null);
 | 
					            bucket.set(index, null);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -22,7 +22,7 @@ comments: true
 | 
				
			|||||||
- 「稳定排序」在完成排序后,**不改变** 相等元素在数组中的相对顺序。
 | 
					- 「稳定排序」在完成排序后,**不改变** 相等元素在数组中的相对顺序。
 | 
				
			||||||
- 「非稳定排序」在完成排序后,相等素在数组中的相对位置 **可能被改变**。
 | 
					- 「非稳定排序」在完成排序后,相等素在数组中的相对位置 **可能被改变**。
 | 
				
			||||||
 | 
					
 | 
				
			||||||
假设我们有一个存储学生信息当表格,第 1, 2 列粉笔是姓名和年龄。那么在以下示例中,「非稳定排序」会导致输入数据的有序性丢失。因此「稳定排序」是很好的特性,**在多级排序中是必须的**。
 | 
					假设我们有一个存储学生信息当表格,第 1, 2 列分别是姓名和年龄。那么在以下示例中,「非稳定排序」会导致输入数据的有序性丢失。因此「稳定排序」是很好的特性,**在多级排序中是必须的**。
 | 
				
			||||||
 | 
					
 | 
				
			||||||
```shell
 | 
					```shell
 | 
				
			||||||
# 输入数据是按照姓名排序好的
 | 
					# 输入数据是按照姓名排序好的
 | 
				
			||||||
 | 
				
			|||||||
@ -119,7 +119,7 @@ comments: true
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
=== "Go"
 | 
					=== "Go"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```go title="deque.go"
 | 
					    ```go title="deque_test.go"
 | 
				
			||||||
    /* 初始化双向队列 */
 | 
					    /* 初始化双向队列 */
 | 
				
			||||||
    // 在 Go 中,将 list 作为双向队列使用
 | 
					    // 在 Go 中,将 list 作为双向队列使用
 | 
				
			||||||
    deque := list.New()
 | 
					    deque := list.New()
 | 
				
			||||||
 | 
				
			|||||||
@ -114,7 +114,7 @@ comments: true
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
=== "Go"
 | 
					=== "Go"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```go title="queue.go"
 | 
					    ```go title="queue_test.go"
 | 
				
			||||||
    /* 初始化队列 */
 | 
					    /* 初始化队列 */
 | 
				
			||||||
    // 在 Go 中,将 list 作为队列来使用
 | 
					    // 在 Go 中,将 list 作为队列来使用
 | 
				
			||||||
    queue := list.New()
 | 
					    queue := list.New()
 | 
				
			||||||
 | 
				
			|||||||
@ -114,7 +114,7 @@ comments: true
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
=== "Go"
 | 
					=== "Go"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ```go title="stack.go"
 | 
					    ```go title="stack_test.go"
 | 
				
			||||||
    /* 初始化栈 */
 | 
					    /* 初始化栈 */
 | 
				
			||||||
    // 在 Go 中,推荐将 Slice 当作栈来使用
 | 
					    // 在 Go 中,推荐将 Slice 当作栈来使用
 | 
				
			||||||
    var stack []int
 | 
					    var stack []int
 | 
				
			||||||
 | 
				
			|||||||
@ -60,5 +60,6 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
/* font-family setting for Win10 */
 | 
					/* font-family setting for Win10 */
 | 
				
			||||||
body {
 | 
					body {
 | 
				
			||||||
  --md-code-font-family: var(--md-code-font, _), SFMono-Regular, Consolas, Menlo, Noto Sans SC, monospace;
 | 
					  --md-text-font-family: -apple-system,BlinkMacSystemFont,var(--md-text-font,_),Helvetica,Arial,sans-serif;
 | 
				
			||||||
 | 
					  --md-code-font-family: var(--md-code-font,_),SFMono-Regular,Consolas,Menlo,-apple-system,BlinkMacSystemFont,var(--md-text-font,_),monospace;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user