std-method
BinaryHeap::into_sorted_vec
Consume the heap and return elements in ascending order according to its ordering. Use this when a complete sorted report is needed. Expected stdout (not executed): [3, 5, 8] Common mistake: Expecting the same descending order as repeated pop calls.
Formal Syntax & Structure
rust syntaxrust
fn into_sorted_vec(self) -> Vec<T>Working Example
Example Snippetrust
fn main() { use std::collections::BinaryHeap; let q = BinaryHeap::from([8, 3, 5]); println!("{:?}", q.into_sorted_vec());}