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.