Skip to content

Commit 69117a9

Browse files
committed
init g
1 parent 617fd49 commit 69117a9

File tree

1 file changed

+41
-4
lines changed

1 file changed

+41
-4
lines changed

Prim.go

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,58 @@ import (
44
"fmt"
55
)
66

7-
var MAX_SIZE = 1000
7+
const MAX_SIZE int = 5
8+
9+
//为了看上去 好一些
10+
const MAX_VALUE int = 9
811

912
func main() {
1013
fmt.Println("Prim")
14+
var gg Graph
15+
var vexs = []string{"A", "B", "C", "D", "E"}
16+
gg.vexnum = 5
17+
gg.vexs = vexs
18+
19+
for i := 0; i < len(vexs); i++ {
20+
for j := 0; j < len(vexs); j++ {
21+
gg.matrix[i][j] = MAX_VALUE
22+
}
23+
}
24+
initGG(&gg)
25+
fmt.Println(gg.vexs)
26+
PrintG(gg, len(vexs))
27+
}
28+
29+
func PrintG(gg Graph, l int) {
30+
for i := 0; i < l; i++ {
31+
fmt.Println(gg.matrix[i])
32+
}
1133
}
1234

1335
type Graph struct {
14-
vexs [MAX_SIZE]string //定点集合
36+
vexs []string //定点集合
1537
vexnum int //定点数量
1638
edgnum int //边数量
17-
matri [MAX_SIZE][MAX_SIZE]int //邻接矩阵
39+
matrix [MAX_SIZE][MAX_SIZE]int //邻接矩阵
1840
}
1941

20-
func init() {
42+
func initGG(gg *Graph) {
43+
gg.matrix[0][1] = 5
44+
gg.matrix[0][2] = 3
45+
46+
gg.matrix[1][0] = 5
47+
gg.matrix[1][3] = 7
48+
gg.matrix[1][4] = 4
49+
50+
gg.matrix[2][0] = 3
51+
gg.matrix[2][3] = 6
52+
53+
gg.matrix[3][1] = 7
54+
gg.matrix[3][2] = 6
55+
gg.matrix[3][4] = 1
2156

57+
gg.matrix[4][1] = 4
58+
gg.matrix[4][3] = 1
2259
}
2360

2461
func prim() {

0 commit comments

Comments
 (0)