pub struct LinkedList<T> { /* private fields */ }
Expand description
A singly-linked list.
This structure represents a LinkedList
where each node stores
a value of type T
and links to the next node in the sequence.
Implementations§
Source§impl<T> LinkedList<T>
impl<T> LinkedList<T>
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new and empty LinkedList
.
§Examples
use dsa::data_structures::linked_list::LinkedList;
let list: LinkedList<i32> = LinkedList::new();
assert!(list.is_empty());
Sourcepub fn push_front(&mut self, value: T)
pub fn push_front(&mut self, value: T)
Adds a value to the front of the LinkedList
.
This method creates a new node containing the given value and makes it the new head of the list.
§Examples
use dsa::data_structures::linked_list::LinkedList;
let mut list = LinkedList::new();
list.push_front(10);
list.push_front(20);
assert!(!list.is_empty());
Sourcepub fn pop_front(&mut self) -> Option<T>
pub fn pop_front(&mut self) -> Option<T>
Removes and returns the value from the front of the LinkedList
.
If the list is empty, this method returns None
. Otherwise,
it removes the head node and returns its value.
§Returns
An Option<T>
optional generic type based on whether the topmost node was popped
from the list
Some
node is returned if thisLinkedList
has a head, otherwiseNone
§Examples
use dsa::data_structures::linked_list::LinkedList;
let mut list = LinkedList::new();
list.push_front(10);
list.push_front(20);
assert_eq!(list.pop_front(), Some(20));
assert_eq!(list.pop_front(), Some(10));
assert!(list.is_empty());
Auto Trait Implementations§
impl<T> Freeze for LinkedList<T>
impl<T> RefUnwindSafe for LinkedList<T>where
T: RefUnwindSafe,
impl<T> Send for LinkedList<T>where
T: Send,
impl<T> Sync for LinkedList<T>where
T: Sync,
impl<T> Unpin for LinkedList<T>
impl<T> UnwindSafe for LinkedList<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more