Advertisement
Guest User

ptrcrash

a guest
Apr 30th, 2020
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.17 KB | None | 0 0
  1. class Node
  2. {
  3. public:
  4.     char symbol;
  5.     int count;
  6.     Node *left = nullptr, *right = nullptr;
  7.     friend bool operator < (const Node &a, const Node &b)
  8.     {
  9.         return a.count < b.count;
  10.     }
  11.     friend bool operator > (const Node &a, const Node &b)
  12.     {
  13.         return a.count > b.count;
  14.     }
  15.  
  16.     Node(char symbol = '\0', int count = 0, Node* left = nullptr, Node* right = nullptr)
  17.     {
  18.         this->symbol = symbol;
  19.         this->count = count;
  20.         this->left = left;
  21.         this->right = right;
  22.     };
  23.  
  24.     Node(Symbol s)
  25.     {
  26.         this->symbol = s.a;
  27.         this->count = s.count;
  28.         this->left = nullptr;
  29.         this->right = nullptr;
  30.     };
  31.  
  32.     Node(Node const& a) : symbol(a.symbol), count(a.count), left(a.left),right(a.right)
  33.     {
  34.         //this->symbol = a.symbol;
  35.         //this->count = a.count;
  36.         //this->left = a.left;
  37.         //this->right = a.right;
  38.     }
  39. };
  40.     priority_queue<Node,vector<Node>, greater<Node>> tree;
  41.     while (tree.size() > 1)
  42.     {
  43.         Node t1 = tree.top();
  44.         tree.pop();
  45.         Node t2 = tree.top();
  46.         tree.pop();
  47.         tree.push(intersect(t1, t2));
  48.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement