Skip to content

Latest commit

 

History

History
31 lines (26 loc) · 682 Bytes

README.md

File metadata and controls

31 lines (26 loc) · 682 Bytes

Linked List

Basic linked list implementation to understand rust ownership & borrowing particularities

Examples

Push and Pop

let mut l = List::new();

l.push_first(1);
l.push_first(2);
l.push_last(3);
l.push_last(4);
// [2,1,3,4]

assert_eq!(l.pop_last(), Some(4));
assert_eq!(l.pop_last(), Some(3));
assert_eq!(l.pop_first(), Some(2));
assert_eq!(l.pop_first(), Some(1));
assert_eq!(l.pop_first(), None);

Collect into Lists for iterating over

let v = vec![1,2,3];

let mut l : List<i32> = v.into_iter().collect();

assert_eq!(l.pop_last(), Some(1));
assert_eq!(l.pop_last(), Some(2));
assert_eq!(l.pop_last(), Some(3));
assert_eq!(l.pop_last(), None);