feat: update tests

This commit is contained in:
2024-01-08 00:16:29 +08:00
parent 97baed2e2a
commit fe5c16450c
4 changed files with 47 additions and 2 deletions

View File

@@ -0,0 +1,30 @@
#[derive(Debug)]
struct Node {
value: i32,
next: Option<Box<Node>>,
}
fn build_chain() -> Option<Box<Node>> {
let mut p = None;
for i in 0..3 {
p = Some(Box::new(Node {
value: i,
next: p,
}));
}
p
}
fn print_chain(mut p: &Option<Box<Node>>) {
let mut values = vec![];
while let Some(node) = p {
values.push(node.value.to_string());
p = &node.next;
}
println!("{}", values.join(" -> "))
}
fn main() {
let p = build_chain();
print_chain(&p);
}