April 2026
Intermediate
631 pages
16h 20m
English
This section provides the code solutions for the practice exercises in Section 11.4. The code is largely self-explanatory; however, we have included comments and additional explanations wherever necessary to enhance understanding.
Implementing the peek method in a linked list
#[derive(Debug)]struct Linklist { head: pointer,}#[derive(Debug)]struct Node { element: i32, next: pointer,}type pointer = Option<Box<Node>>;impl Linklist { fn peek(&self) -> Option<i32> { match &self.head { Some(H) => Some(H.element), None => None, } }}fn main() {}
Making a linked list generic in Rust
#[derive(Debug)]struct Linklist<T> { head: pointer<T>,}#[derive(Debug)]struct Node<T> { element: T, next: pointer<T>,}type pointer<T> = Option<Box ...
Read now
Unlock full access