Struct linked::LinkedList[][src]

pub struct LinkedList<T>(_);
Expand description

LinkedList is an implementation of a singly-linked-list.

Implementations

Create a new empty linked list

Get the length of the linked list. This is an O(n) computation

Determine if this linked list is empty. This is an O(1) computation

Push to the front of the linked list. This is O(1)

let mut ll = LinkedList::new();
ll.push_front(1);
ll.push_front(2);
assert_eq!(ll, LinkedList::from_iter([2, 1]))

Pop from the front of the linked list. This is O(1)

let mut ll = LinkedList::from_iter([1, 2]);
assert_eq!(ll.pop_front(), Some(1));
assert_eq!(ll.pop_front(), Some(2));
assert_eq!(ll.pop_front(), None);

View the first value in the linked list. This is O(1)

Modify the first value in the linked list. This is O(1)

View the last value in the linked list. This is O(n)

Modify the last value in the linked list. This is O(n)

Push to the back of the linked list. This is O(n)

let mut ll = LinkedList::new();
ll.push_back(1);
ll.push_back(2);
assert_eq!(ll, LinkedList::from_iter([1, 2]))

Pop from the back of the linked list. This is O(n)

let mut ll = LinkedList::from_iter([1, 2]);
assert_eq!(ll.pop_back(), Some(2));
assert_eq!(ll.pop_back(), Some(1));
assert_eq!(ll.pop_back(), None);

Create an iter over this linked list

let mut ll = LinkedList::from_iter([1, 2, 3]);
assert_eq!(ll.iter().cloned().collect::<Vec<_>>(), vec![1, 2, 3]);

Create a mutable iter over this linked list

let mut ll = LinkedList::from_iter([1, 2, 3]);
ll.iter_mut().for_each(|i| *i *= 2);
assert_eq!(ll, LinkedList::from_iter([2, 4, 6]));

Add one linked list to the end of this linked list

let mut ll = LinkedList::from_iter(0..3);
ll.append(LinkedList::from_iter(3..6));

assert_eq!(ll, LinkedList::from_iter(0..6));

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Executes the destructor for this type. Read more

Extends a collection with the contents of an iterator. Read more

🔬 This is a nightly-only experimental API. (extend_one)

Extends a collection with exactly one element.

🔬 This is a nightly-only experimental API. (extend_one)

Reserves capacity in a collection for the given number of additional elements. Read more

Creates a value from an iterator. Read more

Which kind of iterator are we turning this into?

The type of the elements being iterated over.

Creates an iterator from a value. Read more

Which kind of iterator are we turning this into?

The type of the elements being iterated over.

Creates an iterator from a value. Read more

Which kind of iterator are we turning this into?

The type of the elements being iterated over.

Creates an iterator from a value. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.