mirror of
https://github.com/krahets/hello-algo.git
synced 2026-08-14 04:30:58 +00:00
Add code source blocks to the chapter Graph.
Fix "函数" and "方法"
This commit is contained in:
@@ -12,7 +12,7 @@ type myList struct {
|
||||
extendRatio int
|
||||
}
|
||||
|
||||
/* 构造函数 */
|
||||
/* 构造方法 */
|
||||
func newMyList() *myList {
|
||||
return &myList{
|
||||
numsCapacity: 10, // 列表容量
|
||||
|
||||
@@ -15,6 +15,7 @@ type vertex struct {
|
||||
val int
|
||||
}
|
||||
|
||||
/* 构造方法 */
|
||||
func newVertex(val int) vertex {
|
||||
return vertex{
|
||||
val: val,
|
||||
@@ -28,7 +29,7 @@ type graphAdjList struct {
|
||||
adjList map[vertex]map[vertex]struct{}
|
||||
}
|
||||
|
||||
/* 构造函数 */
|
||||
/* 构造方法 */
|
||||
func newGraphAdjList(edges [][]vertex) *graphAdjList {
|
||||
g := &graphAdjList{
|
||||
adjList: make(map[vertex]map[vertex]struct{}),
|
||||
|
||||
@@ -14,6 +14,7 @@ type graphAdjMat struct {
|
||||
adjMat [][]int
|
||||
}
|
||||
|
||||
/* 构造方法 */
|
||||
func newGraphAdjMat(vertices []int, edges [][]int) *graphAdjMat {
|
||||
// 添加顶点
|
||||
n := len(vertices)
|
||||
|
||||
@@ -15,14 +15,14 @@ type maxHeap struct {
|
||||
data []any
|
||||
}
|
||||
|
||||
/* 构造函数,建立空堆 */
|
||||
/* 构造方法,建立空堆 */
|
||||
func newHeap() *maxHeap {
|
||||
return &maxHeap{
|
||||
data: make([]any, 0),
|
||||
}
|
||||
}
|
||||
|
||||
/* 构造函数,根据切片建堆 */
|
||||
/* 构造方法,根据切片建堆 */
|
||||
func newMaxHeap(nums []any) *maxHeap {
|
||||
// 将列表元素原封不动添加进堆
|
||||
h := &maxHeap{data: nums}
|
||||
|
||||
@@ -112,7 +112,7 @@ func (t *aVLTree) insert(val int) *TreeNode {
|
||||
return t.root
|
||||
}
|
||||
|
||||
/* 递归插入结点(辅助函数) */
|
||||
/* 递归插入结点(辅助方法) */
|
||||
func (t *aVLTree) insertHelper(node *TreeNode, val int) *TreeNode {
|
||||
if node == nil {
|
||||
return NewTreeNode(val)
|
||||
@@ -140,7 +140,7 @@ func (t *aVLTree) remove(val int) *TreeNode {
|
||||
return root
|
||||
}
|
||||
|
||||
/* 递归删除结点(辅助函数) */
|
||||
/* 递归删除结点(辅助方法) */
|
||||
func (t *aVLTree) removeHelper(node *TreeNode, val int) *TreeNode {
|
||||
if node == nil {
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user