MCPcopy Create free account
hub / github.com/QMHTMY/RustBook / build_graph

Function build_graph

publication/code/chapter09/bfs.rs:73–91  ·  view source on GitHub ↗

根据 data 构建图

(data: [[usize;2];20])

Source from the content-addressed store, hash-verified

71
72// 根据 data 构建图
73fn build_graph(data: [[usize;2];20]) -> Vec<(Graph, usize)> {
74 let mut graphs: Vec<(Graph, usize)> = Vec::new();
75
76 for _ in 0..9 {
77 graphs.push((Graph::new(), 0));
78 }
79
80 for i in 1..9 {
81 for j in 0..data.len() {
82 if data[j][0] == i {
83 graphs[i].0.insert(data[j][1]);
84 }
85 }
86 print!("[{i}]->");
87 graphs[i].0.print_node();
88 }
89
90 graphs
91}
92
93fn bfs(graph: Vec<(Graph, usize)>) {
94 let mut gp = graph;

Callers 1

mainFunction · 0.70

Calls 4

pushMethod · 0.45
lenMethod · 0.45
insertMethod · 0.45
print_nodeMethod · 0.45

Tested by

no test coverage detected