Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pub mod base {
- use std::fmt::Debug;
- #[derive(Default, Debug, Clone)]
- pub struct MaxComparator {}
- pub trait Comparator: Default + Debug + Clone {}
- impl Comparator for MaxComparator {}
- #[derive(Debug)]
- pub struct BinaryHeap<T, C>
- {
- vec: Vec<T>,
- cmp: C,
- }
- impl<T, C> From<Vec<T>> for BinaryHeap<T, C>
- where C: Comparator
- {
- fn from(vec: Vec<T>) -> Self {
- BinaryHeap {
- vec,
- cmp: C::default(),
- }
- }
- }
- }
- pub type BinaryHeap<T> = base::BinaryHeap<T, base::MaxComparator>;
- fn main() {
- let heap = BinaryHeap::from(vec![0, 1, 2]);
- println!("{:?}", heap);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement