How to use LinkedList in Rust

Use std::collections::LinkedList to manage a doubly-linked list with constant-time insertion and removal at both ends.

Use std::collections::LinkedList to create a doubly-linked list that allows pushing and popping elements at either end in constant time.

use std::collections::LinkedList;

let mut list = LinkedList::new();
list.push_back(1);
list.push_front(2);
println!("{:?}", list); // [2, 1]

Note: Prefer Vec or VecDeque for better performance and memory efficiency unless you specifically need constant-time insertion at both ends.