Struct Double

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

Double is a double linked list referencing the head, the tail node node and the length of the list.

Implementations§

Source§

impl<T> Double<T>
where T: Debug + PartialEq + Clone,

Source

pub fn new() -> Self

Create a new instance of the Double linked list.

Source

pub fn append(&mut self, value: T)

Append a new value to the end of the list.

Source

pub fn remove(&mut self, value: T) -> Result<bool, Error>

Remove a node from the list. Returns true if the value is found and removed. If the value is not found, it returns an error.

Source

pub fn search(&self, value: T) -> Result<bool, Error>

Search for a value in the list, returns true if the value is found. If the value is not found, it returns an error.

Source

pub fn update(&mut self, old_value: T, new_value: T) -> Result<bool, Error>

Update a value in the list, returns true if the value is found and updated. If the value is not found, it returns an error.

Source

pub fn from_vec(values: Vec<T>) -> Self

Create a new instance of the double linked list from a vector.

Source

pub fn pop(&mut self) -> Result<Option<T>, Error>

Remove the last node from the list. Returns the value of the removed node. If the list is empty, it returns an error.

Source

pub fn print(&self)

Source

pub fn is_empty(&self) -> bool

Check if the list is empty.

Source

pub fn get(&self, index: usize) -> Result<Option<T>, Error>

Get an element from the list by index. Returns an error if the list is empty or the index is out of bounds. If the index is valid, it returns the value of the node.

Trait Implementations§

Source§

impl<T: Debug> Debug for Double<T>

Source§

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

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

impl<T> Default for Double<T>
where T: Debug + PartialEq + Clone,

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<T> Freeze for Double<T>

§

impl<T> !RefUnwindSafe for Double<T>

§

impl<T> !Send for Double<T>

§

impl<T> !Sync for Double<T>

§

impl<T> Unpin for Double<T>

§

impl<T> !UnwindSafe for Double<T>

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.