tree

package
v0.0.0-...-bc502ad Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 7, 2023 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Node

type Node struct {
	Value       int
	Left, Right *Node
}

func CreateNode

func CreateNode(value int) *Node

工厂函数,其他语言中的构造函数。注意,返回的是局部变量的内存地址

func (*Node) MaxDepth

func (node *Node) MaxDepth() int
非递归的方式求树的深度,广度优先遍历tree。

LeetCode的题,求树的最大深度:https://leetcode-cn.com/problems/maximum-depth-of-binary-tree/submissions/

func (Node) Print

func (node Node) Print()

treeNode的方法-结构体接受者,函数名前面定义了一个接受者,表明该函数是结构体treeNode的一个方法,固俗称方法,下面定义的方法是值传递,无法改变接受者的内容

func (*Node) SetValue

func (node *Node) SetValue(value int)

treeNode的方法-结构体指针接受者,定义指针接受者才可以改变接受者的数据(引用传递),这种引用传递时主意判断指针是不是nil

func (*Node) Traverse

func (node *Node) Traverse()

遍历节点

func (*Node) TraverseByChannel

func (node *Node) TraverseByChannel() chan *Node

通过channel的方式,来遍历树(可以通过channel输出的遍历节点做自己的事),效果上来讲和TraverseFunc(回调函数的方式)遍历有异曲同工之妙

func (*Node) TraverseFunc

func (node *Node) TraverseFunc(f func(*Node))

传递一个方法遍历树

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL