Performance

Vec vs LinkedList vs VecDeque — Which to Use?

Choose Vec for general lists, VecDeque for queues, and avoid LinkedList due to poor performance.

Use Vec for most cases, VecDeque for queues, and avoid LinkedList due to poor cache performance.

use std::collections::{VecDeque, LinkedList};

// Best for random access and iteration
let mut vec = Vec::new();
vec.push(1);

// Best for pushing/popping from both ends (queue/stack)
let mut deque = VecDeque::new();
deque.push_front(1);
deque.push_back(2);

// Avoid: slow iteration and high memory overhead
let mut list = LinkedList::new();
list.push_back(3);