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

Function palindrome_checker

code/chapter03/palindrome_checker.rs:46–62  ·  view source on GitHub ↗

回文检查

(pal: &str)

Source from the content-addressed store, hash-verified

44
45// 回文检查
46fn palindrome_checker(pal: &str) -> bool {
47 let mut d = Deque::new(pal.len());
48 for c in pal.chars() {
49 let _r = d.add_rear(c); // 数据入队列
50 }
51
52 let mut is_pal = true;
53 while d.size() > 1 && is_pal {
54 let head = d.remove_front();
55 let tail = d.remove_rear();
56 if head != tail { // 比较首尾字符, 若不同则非回文
57 is_pal = false;
58 }
59 }
60
61 is_pal
62}
63
64fn main() {
65 let pal = "rustsur";

Callers 1

mainFunction · 0.70

Calls 5

lenMethod · 0.45
add_rearMethod · 0.45
sizeMethod · 0.45
remove_frontMethod · 0.45
remove_rearMethod · 0.45

Tested by

no test coverage detected