Filename: HuffmanTreeNode.h

 

#ifndef _HUFFMAN_TREE_NODE_H_ 

#define _HUFFMAN_TREE_NODE_H_

 

 

#include <iostream>

using namespace std;

 

//forward definition

class HuffmanTreeNode;

 

typedef HuffmanTreeNode * HuffmanTreeNodePtr;

 

class HuffmanTreeNode 

{

public:

 

            /*

            Purpose: defualt constructor, constructs a HuffmanTreeNode

            Precondtion: none

            Postcondition: character will be initialized to ' ', frequency will be initialize to 0, right and left will be initilized to NULL, and a HuffmanTreeNode object will exist

            */

            HuffmanTreeNode();

 

            /*

            Purpose: constructor, constructs a HuffmanTreeNode with values passed to it

            Precondition: char InCharacter, int InFrequency, HuffmanTreeNodePtr InLeft, HuffmanTreeNodePtr InRight must be passed to the constructor

Postcondition: character will be initialize to InCharacter, frequency will be initialized to InFrequency, left will be initialize to InLeft and right will be initialized to InRight, and HuffmanTreeNode object will exist

            */

            HuffmanTreeNode(char InCharacter, int InFrequency, HuffmanTreeNodePtr InLeft, HuffmanTreeNodePtr InRight);

           

            /*

            Purpose: copy constructor, construct a HuffmanTreeNode from an existing HuffmanTreeNode

            Precondition: a HuffmanTreeNode, from which to copy, must be passed

            Postcondition: a HuffmanTreeNode object will exist

            */

            HuffmanTreeNode(const HuffmanTreeNode & InHuffmanTreeNode);

           

            /*

            Purpose: destructor, destroys an existing HuffmanTreeNode

            Precondition: none

            Postcondition: none

            */

            ~HuffmanTreeNode();

 

            /*

            Purpose: to retrieve the value of the right pointer

            Precondition: none

            Postcondition: a HuffmanTreeNodePtr is returned with the value of the right pointer in the HuffmanTreeNode

            */

            inline HuffmanTreeNodePtr GetRight() const { return right; }

           

            /*

            Purpose: to retrieve the value of the left pointer

            Precondition: none

            Postcondition: a HuffmanTreeNodePtr is returned with the value of the left pointer in the HuffmanTreeNode

            */

            inline HuffmanTreeNodePtr GetLeft() const { return left; }

           

            /*

            Purpose: to retreive the value of the character in the HuffmanTreeNode

            Precondition: none

            Postcondition: a char is returned with the value of the character in the HuffmanTreeNode

            */

            inline char GetCharacter() const { return character; }

           

            /*

            Purpose: to retrive the value of the frequency in the HuffmanTreeNode

            Precondition: none

            Postcondition: an int is returned with the value of the frequency of the HuffmanTreeNode

            */

            inline int GetFrequency() const { return frequency; }

 

 

            /*

            Purpose: to set the value of the right pointer of the HuffmanTreeNode

            Preconditon: a HuffmanTreeNodePtr InNewNode must be passed

            Postcondition: right will now point to the the HuffmanTreeNode specified by HuffmanTreeNodePtr

            */

            inline void SetRight(HuffmanTreeNodePtr InNewNode) { right=InNewNode; }

 

            /*

            Purpose: to set the value of the left pointer of the HuffmanTreeNode

            Preconditon: a HuffmanTreeNodePtr InNewNode must be passed

            Postcondition: left will now point to the the HuffmanTreeNode specified by HuffmanTreeNodePtr

            */

            inline void SetLeft(HuffmanTreeNodePtr InNewNode) { left=InNewNode; }

 

            /*

            Purpose: to set the value of character of the HuffmanTreeNode

            Preconditon: a char InNewCharacter must be passed

            Postcondition: the value of character will now be set to InNewCharacter

            */

            inline void SetCharacter(char InNewCharacter) { character = InNewCharacter; }

 

            /*

            Purpose: to set the value of the left pointer of the HuffmanTreeNode

            Preconditon: an int InNewFrequency must be passed

            Postcondition: the value of frequency will now be set to InNewFrequency

            */

            inline void SetFrequency(int InNewFrequency) { frequency = InNewFrequency; }

 

            /*

            Purpose: to incremenet the frequency of the HuffmanTreeNode

            Preconditon: none

            Postcondition: the value of frequency will now be incrememnted by 1

            */

            inline void IncrementFrequency() { frequency++; }

           

 

            /*

            Purpose: to determine if the HuffmanTreeNode is a leaf

            Preconditon: none

            Postcondition: true is returned if the HuffmanTreeNode is a leaf, false if it is not

            */

            inline bool IsLeaf(){ return (left==NULL && right==NULL); }

 

           

private:

 

            HuffmanTreeNodePtr left;

            HuffmanTreeNodePtr right;

            int frequency;

            char character;

 

 

 

};

 

#endif