24 releases
0.1.26 | May 30, 2021 |
---|---|
0.1.25 | May 28, 2021 |
0.1.7 | Apr 30, 2021 |
#2480 in Data structures
43 downloads per month
9KB
129 lines
priority_queue
Description
Priority Queue is more specialized data structure than Queue. Like ordinary queue, priority queue has same method but with a major difference. In Priority queue items are ordered by key value so that item with the lowest value of key is at front and item with the highest value of key is at rear or vice versa. So we're assigned priority to item based on its key value. Lower the value, higher the priority. Following are the principal methods of a Priority Queue.
How To Use
fn main() {
let mut queue = PriorityQueue::new();
for priority in 10..10000 {
queue.push(priority, String::from(format!("HelloWorld{}", priority)));
}
if let Some(t) = queue.peek() {
println!("peek {}", t);
}
for priority in 0..10 {
let value = queue.pop();
if let Some(t) = value {
println!("pop {}", t);
}
}
if let Some(t) = queue.peek() {
println!("peek {}", t);
}
}
License
This library is licensed under MIT license. See LICENSE for details.