Complete the code to create an empty max heap using Rust's standard library.
let mut heap = std::collections::BinaryHeap::[1]();default() which also works but is less explicit here.with_capacity() requires a size argument.The new() function creates an empty BinaryHeap in Rust.
Complete the code to add an element 10 to the heap.
heap.[1](10);
insert() which is not a method of BinaryHeap.add() or enqueue() which do not exist here.The push() method adds an element to the BinaryHeap in Rust.
Fix the error in the code to remove the largest element from the heap.
let max = heap.[1]();remove() which requires an index and is not available.extract() or delete() which do not exist.The pop() method removes and returns the largest element from a max heap in Rust.
Fill both blanks to create a min heap by reversing the order of elements.
use std::cmp::[1]; let mut min_heap = std::collections::BinaryHeap::new(); min_heap.push([2](5));
Ordering which is an enum, not a wrapper.PartialOrd or Ord directly.Wrapping elements with Reverse makes the max heap behave like a min heap by reversing the comparison order.
Fill all three blanks to build a heap from a vector and pop the largest element.
let data = vec![3, 1, 4]; let mut heap = std::collections::BinaryHeap::[1](data); let largest = heap.[2](); println!("Largest: {}", largest.[3]());
new() which creates an empty heap.BinaryHeap::from() builds a heap from a vector. pop() removes the largest element. unwrap() extracts the value from the Option.
