std-method
BinaryHeap::into_vec
Consume the queue and recover a vector in unspecified element order. Sorting the result explicitly is necessary for a predictable ordered report. Expected stdout (not executed): [2, 4, 7] Common mistake: Treating into_vec as a sorted conversion.
Formal Syntax & Structure
rust syntaxrust
fn into_vec(self) -> Vec<T>Working Example
Example Snippetrust
fn main() { use std::collections::BinaryHeap; let q = BinaryHeap::from([7, 2, 4]); let mut values = q.into_vec(); values.sort_unstable(); println!("{values:?}");}