rust_algorithm_club::collections

Struct SinglyLinkedList

Source
pub struct SinglyLinkedList<T> { /* private fields */ }
Expand description

Implementations§

Source§

impl<T> SinglyLinkedList<T>

Source

pub fn new() -> Self

Constructs a new, empty SinglyLinkedList<T>.

The list will not allocate until elements are pushed onto it.

Source

pub fn push_front(&mut self, elem: T)

Prepends the given element value to the beginning of the container.

§Parameters
  • elem - The element to prepend.
§Complexity

Constant.

Source

pub fn pop_front(&mut self) -> Option<T>

Removes and returns the first element of the container. If there are no elements in the container, return None.

§Complexity

Constant.

Source

pub fn insert_after(&mut self, pos: usize, elem: T) -> Result<(), usize>

Inserts an element after the specified position in the container.

If the position is out of bound, returns an Result:Err with the size of the list.

§Parameters
  • pos - The index after which the element will be inserted.
  • elem - The element to be inserted.
§Complexity

Search time O(n) + O(1).

Source

pub fn remove(&mut self, pos: usize) -> Option<T>

Removes and returns an element at specified position from the container.

§Parameters
  • pos - The index at which the element will be moved.
§Complexity

Search time O(n) + constant.

Source

pub fn clear(&mut self)

Removes all elements from the container.

§Complexity

Linear in the size of the container.

Source

pub fn is_empty(&self) -> bool

Checks whether the container is empty.

§Complexity

Constant.

Source

pub fn len(&self) -> usize

Gets the number of elements in the container.

§Complexity

Linear in the size of the container.

Source

pub fn reverse(&mut self)

Reverses the order of the elements in the container.

§Complexity

Linear in the size of the container.

Source

pub fn iter(&self) -> Iter<'_, T>

Creates an iterator that yields immutable reference of each element.

Source

pub fn iter_mut(&mut self) -> IterMut<'_, T>

Creates an iterator that yields mutable reference of each element.

Trait Implementations§

Source§

impl<T: Debug> Debug for SinglyLinkedList<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Drop for SinglyLinkedList<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T> IntoIterator for SinglyLinkedList<T>

Source§

fn into_iter(self) -> Self::IntoIter

Creates a consuming iterator, that is, one that moves each value out of the list (from start to end). The list cannot be used after calling this.

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?
Source§

impl<T: PartialEq> PartialEq for SinglyLinkedList<T>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl<T> Freeze for SinglyLinkedList<T>

§

impl<T> RefUnwindSafe for SinglyLinkedList<T>
where T: RefUnwindSafe,

§

impl<T> Send for SinglyLinkedList<T>
where T: Send,

§

impl<T> Sync for SinglyLinkedList<T>
where T: Sync,

§

impl<T> Unpin for SinglyLinkedList<T>

§

impl<T> UnwindSafe for SinglyLinkedList<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.