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

Function build_graph

publication/code/chapter09/dfs.rs:68–84  ·  view source on GitHub ↗

构建图

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

Source from the content-addressed store, hash-verified

66
67// 构建图
68fn build_graph(data: [[usize;2];20]) -> Vec<(Graph, usize)> {
69 let mut graphs: Vec<(Graph, usize)> = Vec::new();
70
71 for _ in 0..9 { graphs.push((Graph::new(), 0)); }
72
73 for i in 1..9 {
74 for j in 0..data.len() {
75 if data[j][0] == i {
76 graphs[i].0.insert(data[j][1]);
77 }
78 }
79 print!("[{i}]->");
80 graphs[i].0.print_node();
81 }
82
83 graphs
84}
85
86fn dfs(graph: Vec<(Graph, usize)>) {
87 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