Skip to main content

priority_queue/
priority_queue.rs

1use zigzag_alloc::alloc::system::SystemAllocator;
2use zigzag_alloc::collections::{ExPriorityQueue, OrdContext};
3
4struct MinIntContext;
5impl OrdContext<i32> for MinIntContext {
6    fn less(&self, a: &i32, b: &i32) -> bool {
7        a > b
8    }
9}
10
11fn main() {
12    let alloc = SystemAllocator;
13    let ctx = MinIntContext;
14
15    let mut pq = ExPriorityQueue::new(&alloc, ctx);
16
17    pq.push(50);
18    pq.push(10);
19    pq.push(30);
20
21    let data = [5, 1, 100];
22    pq.push_slice(&data);
23
24    while let Some(top) = pq.pop() {
25        println!("Pop: {}", top);
26    }
27}