pub struct Queue<T> { /* private fields */ }
Expand description
A queue data structure with a fixed capacity.
This structure implements a simple queue where elements of type T
are
enqueued and dequeued according to the First-In-First-Out (FIFO) principle.
Implementations§
Source§impl<T> Queue<T>
impl<T> Queue<T>
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new, empty Queue
.
§Examples
use dsa::data_structures::queue::Queue;
let queue: Queue<i32> = Queue::new();
assert!(queue.is_empty());
Sourcepub fn enqueue(&mut self, value: T)
pub fn enqueue(&mut self, value: T)
Adds a value to the rear of the Queue
.
§Examples
use dsa::data_structures::queue::Queue;
let mut queue = Queue::new();
queue.enqueue(10);
queue.enqueue(20);
assert_eq!(queue.peek(), Some(&10));
Sourcepub fn dequeue(&mut self) -> Option<T>
pub fn dequeue(&mut self) -> Option<T>
Removes and returns the value at the front of the Queue
.
§Examples
use dsa::data_structures::queue::Queue;
let mut queue = Queue::new();
queue.enqueue(10);
queue.enqueue(20);
assert_eq!(queue.dequeue(), Some(10));
assert_eq!(queue.dequeue(), Some(20));
assert!(queue.dequeue().is_none());
Sourcepub fn peek(&self) -> Option<&T>
pub fn peek(&self) -> Option<&T>
Returns a reference to the value at the front without removing it.
§Examples
use dsa::data_structures::queue::Queue;
let mut queue = Queue::new();
queue.enqueue(10);
queue.enqueue(20);
assert_eq!(queue.peek(), Some(&10));
Auto Trait Implementations§
impl<T> Freeze for Queue<T>
impl<T> RefUnwindSafe for Queue<T>where
T: RefUnwindSafe,
impl<T> !Send for Queue<T>
impl<T> !Sync for Queue<T>
impl<T> Unpin for Queue<T>
impl<T> UnwindSafe for Queue<T>where
T: RefUnwindSafe + 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