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

Function create_graph

code/chapter08/dfs.rs:66–82  ·  view source on GitHub ↗

构建图

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

Source from the content-addressed store, hash-verified

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