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

Function main

code/chapter08/word_ladder.rs:215–234  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

213}
214
215fn main() {
216 let words = vec![
217 "FOOL", "COOL", "POOL", "FOUL", "FOIL",
218 "FAIL", "FALL", "POLL", "PALL", "POLE",
219 "PALE", "SALE", "PAGE", "SAGE",
220 ];
221 let len = words.len();
222 let mut g = build_word_graph(words);
223
224 // 首节点加入队列表明正被探索,所以颜色变为灰色
225 g.vertices.get_mut("FOOL").unwrap().color = Color::Gray;
226
227 // 取出首尾点
228 let start = g.vertices.get("FOOL").unwrap().clone();
229 let end = g.vertices.get("SAGE").unwrap().clone();
230
231 // 计算最小转换次数,也就是距离
232 let distance = word_ladder(&mut g, start, end, len);
233 println!("the shortest distance: {distance}");
234}

Callers

nothing calls this directly

Calls 5

build_word_graphFunction · 0.70
word_ladderFunction · 0.70
lenMethod · 0.45
get_mutMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected