std-method
LinkedList::split_off
Keep the prefix before index at and return the suffix as a separate list. At may equal len; a larger index panics. Finding the split point involves traversal. Expected stdout (not executed): [10, 20] [30, 40] Common mistake: Assuming that an arbitrary indexed split is constant time.
Formal Syntax & Structure
rust syntaxrust
fn split_off(&mut self, at: usize) -> LinkedList<T>Working Example
Example Snippetrust
fn main() { use std::collections::LinkedList; let mut a = LinkedList::from([10, 20, 30, 40]); let b = a.split_off(2); println!("{:?}", a.into_iter().collect::<Vec<_>>()); println!("{:?}", b.into_iter().collect::<Vec<_>>());}