fn pop_smallest<V: PartialOrd>(
    leaves: &mut Vec<HuffmanTree<V>>,
    nodes: &mut VecDeque<HuffmanTree<V>>,
) -> HuffmanTree<V> {
    if let Some(leaf) = leaves.pop() {
        if let Some(node) = nodes.pop_back() {
            if leaf.value() <= node.value() {
                nodes.push_back(node);
                leaf
            } else {
                leaves.push(leaf);
                node
            }
        } else {
            leaf
        }
    } else {
        nodes.pop_back().unwrap()
    }
}
/// This is a helper function to build a HuffmanTree.
///
/// It pops the smallest leaf/partial tree in both queues, favoring leaves to
/// minimize unbalance in the resulting tree.
This is a helper function to build a HuffmanTree.
It pops the smallest leaf/partial tree in both queues, favoring leaves to
minimize unbalance in the resulting tree.
This is a helper function to build a HuffmanTree . It pops the smallest leaf / partial tree in both queues favoring leaves to minimize unbalance in the resulting tree .
fn pop_smallest<V: PartialOrd>(
    leaves: &mut Vec<HuffmanTree<V>>,
    nodes: &mut VecDeque<HuffmanTree<V>>,
) -> HuffmanTree<V> {
    if let Some(leaf) = leaves.pop() {
        if let Some(node) = nodes.pop_back() {
            if leaf.value() <= node.value() {
                nodes.push_back(node);
                leaf
            } else {
                leaves.push(leaf);
                node
            }
        } else {
            leaf
        }
    } else {
        nodes.pop_back().unwrap()
    }
}
fn pop_smallest < V : PartialOrd > ( leaves : & mut Vec < HuffmanTree < V > > , nodes : & mut VecDeque < HuffmanTree < V > > , ) -> HuffmanTree < V > { if let Some ( leaf ) = leaves . pop ( ) { if let Some ( node ) = nodes . pop_back ( ) { if leaf . value ( ) <= node . value ( ) { nodes . push_back ( node ) ; leaf } else { leaves . push ( leaf ) ; node } } else { leaf } } else { nodes . pop_back ( ) . unwrap ( ) } }
This is a helper function to build a HuffmanTree.
This is a helper function to build a HuffmanTree .
leaves
&mut Vec<HuffmanTree<V>>
nodes
&mut VecDeque<HuffmanTree<V>>
leaves
&mut Vec<HuffmanTree<V>>
nodes
&mut VecDeque<HuffmanTree<V>>