Advertisement
Guest User

CharCountNode.cpp

a guest
Apr 2nd, 2014
607
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class CharCountNode
  2. {
  3. private:
  4.     char character;
  5.     int count;
  6. public:
  7.     CharCountNode * left;
  8.     CharCountNode * right;
  9.  
  10.     CharCountNode()
  11.     {
  12.         character = '~';
  13.         count = 0;
  14.         left = right = NULL;
  15.     }
  16.  
  17.     CharCountNode(char c, int n)
  18.     {
  19.         character = c;
  20.         count = n;
  21.         left = right = NULL;
  22.     }
  23.  
  24.     ~CharCountNode()
  25.     {
  26.         delete right;
  27.         right = NULL;
  28.  
  29.         delete left;
  30.         left = NULL;
  31.     }
  32.  
  33.     CharCountNode(const CharCountNode & rhs)
  34.     {
  35.         character = rhs.character;
  36.         count = rhs.count;
  37.  
  38.         if (rhs.left == NULL)
  39.             left = NULL;
  40.         else
  41.             left = new CharCountNode(*rhs.left);
  42.  
  43.         if (rhs.right == NULL)
  44.             right = NULL;
  45.         else
  46.             right = new CharCountNode(*rhs.right);
  47.     }
  48.  
  49.     CharCountNode operator=(const CharCountNode & rhs)
  50.     {
  51.         character = rhs.character;
  52.         count = rhs.count;
  53.  
  54.         if (rhs.left == NULL)
  55.             left = NULL;
  56.         else
  57.             left = new CharCountNode(*rhs.left);
  58.  
  59.         if (rhs.right == NULL)
  60.             right = NULL;
  61.         else
  62.             right = new CharCountNode(*rhs.right);
  63.  
  64.         return *this;
  65.     }
  66.  
  67.     char getCharacter()
  68.     { return character; }
  69.  
  70.     int getCount()
  71.     { return count; }
  72.  
  73.     bool operator<(const CharCountNode & rhs) const
  74.     { return count < rhs.count; }
  75.  
  76.     bool operator>(const CharCountNode & rhs) const
  77.     { return count > rhs.count; }
  78.  
  79. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement