23.16 LinkedLists
LinkedLists
Overview
A LinkedList is a linear data structure where each element (node) contains a value and a pointer to the next node.
Topics
- Singly Linked List
- Doubly Linked List
- Operations (Insertion, Deletion, Traversal)
Examples
Singly Linked List
use std::rc::Rc;
struct Node {
value: i32,
next: Option<Rc<Node>>,
}
let node1 = Rc::new(Node { value: 1, next: None });
let node2 = Rc::new(Node { value: 2, next: Some(node1.clone()) });
println!("Node 2 value: {}", node2.value);