std-method
BinaryHeap::push
Transfer an item into the queue and maintain the priority invariant. A newly inserted item may immediately become the top. Expected stdout (not executed): Some(10) Common mistake: Treating push as ordinary insertion at the end of a sorted array.
Formal Syntax & Structure
rust syntaxrust
fn push(&mut self, item: T)Working Example
Example Snippetrust
fn main() { use std::collections::BinaryHeap; let mut queue = BinaryHeap::from([4, 6]); queue.push(10); println!("{:?}", queue.peek());}