8000 update · mohuishou/go-algorithm@56abe47 · GitHub
[go: up one dir, main page]

Skip to content

Commit 56abe47

Browse files
committed
update
1 parent 2559768 commit 56abe47

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

Graph/Graph.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,16 @@ type VextexNode struct {
3131
}
3232

3333
//Graph 图
34-
type Graph []VextexNode
34+
type Graph struct {
35+
VNum, ENum int //顶点数目,边数目
36+
G []VextexNode //邻接表
37+
}
3538

3639
//CreateGraph 创建邻接表
3740
func CreateGraph(n int) (graph Graph) {
38-
graph = make(Graph, n)
41+
graph.G = make([]VextexNode, n)
3942
for i := 0; i < n; i++ {
40-
graph[i] = VextexNode{}
43+
graph.G[i] = VextexNode{}
4144
}
4245
return graph
4346
}
@@ -47,8 +50,8 @@ func (graph Graph) AddEdge(s, t VextexType, weight EdgeType) {
4750
edge := &EdgeNode{v: t, weight: weight}
4851

4952
//添加边到头部
50-
edge.next = graph[s].FisrtEdge
51-
graph[s].FisrtEdge = edge
53+
edge.next = graph.G[s].FisrtEdge
54+
graph.G[s].FisrtEdge = edge
5255
}
5356

5457
//BuildGraph 通过读取文件建图

ShortestPath/Dijkstra.go

Lines changed: 13 additions & 1 deletion
7977
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
package ShortestPath
22

3+
import (
4+
"github.com/mohuishou/algorithm/Graph"
5+
)
6+
37
//Dijkstra 算法
4-
func Dijkstra() {
8+
//一种求单源最短路径的算法
9+
func Dijkstra(graph Graph.Graph, s int, dist, path []int) {
10+
var (
11+
visited []bool //是否已经查看过
12+
)
13+
//初始化
14+
for i := 0; i < graph.VNum; i++ {
15+
16+
}
517

618
}

0 commit comments

Comments
 (0)
0