mortified_penguin

huff_node.hpp

Dec 29th, 2012
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. #ifndef NODE_HPP
  2. #define NODE_HPP
  3.  
  4. #include <functional>
  5. #include <typeinfo>
  6. #include <iostream>
  7.  
  8. enum struct nodetype: bool
  9. {
  10.    BRANCH,
  11.    LEAF
  12. };
  13.  
  14. struct node
  15. {
  16.       int weight;
  17.       node *left;
  18.       node *right;
  19.  
  20.       virtual nodetype type() const = 0;
  21.       node(node *left_, node *right_, int weight_ = 0);
  22.       virtual ~node() = 0;
  23. };
  24.  
  25. struct branch: public node
  26. {
  27.       virtual nodetype type() const;
  28.  
  29.       branch(node *left_, node *right_): node(left_, right_) {}
  30.  
  31. };
  32.  
  33. struct leaf: public node
  34. {
  35.       char payload;
  36.  
  37.       virtual nodetype type() const;
  38.  
  39.       leaf(char payload_, int weight_): node(nullptr, nullptr, weight_), payload(payload_) { }
  40. };
  41.  
  42.  
  43.  
  44. struct node_comp: public std::binary_function<node*, node*, bool>
  45. {
  46.       bool operator()(const node* N1, const node* N2);
  47. };
  48.  
  49. #endif // NODE_HPP
Advertisement
Add Comment
Please, Sign In to add comment