1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
| use std::collections::BinaryHeap;
use std::cmp::Reverse;
let mut heap = BinaryHeap::new();
heap.push(10);
heap.push(3);
heap.push(18);
assert!(heap.len, 3);
assert!(heap.pop(), Some(18));
assert!(heap.len, 2);
assert!(heap.pop(), Some(10));
assert!(heap.len, 1);
assert!(heap.pop(), Some(3));
assert!(heap.len, 0);
assert!(heap.pop(), None);
heap.push(Reverse(10));
heap.push(Reverse(3));
heap.push(Reverse(18));
assert!(heap.len, 3);
assert!(heap.pop(), Some(Reverse(3)));
assert!(heap.len, 2);
assert!(heap.pop(), Some(Reverse(10)));
assert!(heap.len, 1);
assert!(heap.pop(), Some(Reverse(18)));
assert!(heap.len, 0);
assert!(heap.pop(), None);
|