Loading RustViz Engine...
Build a recursive stack data structure with Box indirection and proper RAII drop.
This problem is currently in blueprint template mode. Once the concept foundation is finalized, live in-browser WebAssembly compilation and test assertion runners will be enabled here.
pub struct List<T> {
head: Option<Box<Node<T>>>,
}
struct Node<T> {
elem: T,
next: Option<Box<Node<T>>>,
}
impl<T> List<T> {
pub fn new() -> Self { Self { head: None } }
pub fn push(&mut self, elem: T) {
let new_node = Box::new(Node {
elem,
next: self.head.take(),
});
self.head = Some(new_node);
}
}