#include <vector>
#include <iostream>
#include <memory>
class huffman_node
{
public:
        bool internal_;
        char symbol_;
        int freq_;
        std::unique_ptr<huffman_node> left_;
        std::unique_ptr<huffman_node> right_;
public:
        huffman_node() : internal_(true), symbol_('?') {}
        huffman_node(char symb, int freq): internal_(false),
                                           symbol_(symb),
                                           freq_(freq) {}
        huffman_node(huffman_node& other)
        {
                internal_ = other.internal_;
                symbol_ = other.symbol_;
                freq_ = other.freq_;
                left_ = std::move(other.left_);
                right_ = std::move(other.right_);
        }
        huffman_node & operator=(huffman_node& other)
        {
                internal_ = other.internal_;
                symbol_ = other.symbol_;
                freq_ = other.freq_;
                left_ = std::move(other.left_);
                right_ = std::move(other.right_);
                return *this;
        }
        ~huffman_node() {}
};

class huffman_encoder
{
public:
        void make_huffman(
                const std::vector<int>& freq,
                const std::vector<char>& symb)
        {
                std::vector<std::unique_ptr<huffman_node>> nodes;
                for (int i = 0; i < freq.size(); ++i)
                {
                        std::unique_ptr<huffman_node> ph(new huffman_node(symb[i], freq[i]));
                        if (ph)
                                nodes.push_back(std::move(ph));
                }
                print_node(nodes);
        }

        void print_node(std::vector<std::unique_ptr<huffman_node>>& nodes)
        {
                for (int i = 0; i < nodes.size(); ++i)
                {
                        std::unique_ptr<huffman_node> p = std::move(nodes[i]);
                        std::cout << "symbol: " << p->symbol_ << " frequency: " << p->freq_ << std::endl;
                        nodes[i] = std::move(p);
                }
        }
};

int main()
{
        std::vector<char> sym = {'a', 'b', 'c', 'd'};
        std::vector<int> freq = { 5,   1,   3,   9};
        huffman_encoder he;
        he.make_huffman(freq, sym);
        return 0;
}