graph

package
v0.0.0-...-b071cee Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2023 License: GPL-3.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidNode = errors.New("非法节点")
	ErrInvalidEdge = errors.New("非法边")
)

Functions

This section is empty.

Types

type Graph

type Graph struct {
	// contains filtered or unexported fields
}

Graph is a directed graph represented by adjacency Matrix

func NewGraphByMatrix

func NewGraphByMatrix(matrix [][]int) *Graph

func NewRawGraph

func NewRawGraph(nodeNum int) *Graph

func (*Graph) AddEdge

func (g *Graph) AddEdge(n, m int, v int) error

AddEdge 添加一条从n指向m,权值为v的边

func (*Graph) BFS

func (g *Graph) BFS(op func(n int))

BFS 广度优先搜索

func (*Graph) DFS

func (g *Graph) DFS(op func(n int))

DFS 深度优先搜索

func (*Graph) DelEdge

func (g *Graph) DelEdge(n, m int) error

DelEdge 删除从n指向m的边

func (*Graph) HasEdge

func (g *Graph) HasEdge(n, m int) int

HasEdge 检查从n到m是否有边,若有返回边权值,否则返回0

func (*Graph) Neighbors

func (g *Graph) Neighbors(n int) ([]int, error)

Neighbors 获取结点n的所有“邻居”,即一步内可到达n或n可到达的结点

Jump to

Keyboard shortcuts

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