Viewing file: c/huffman1/Node.cpp | Back to directory listing
Author: Loren Segal | Last modified: February 21 2006 12:00 am | Download

#include "huffman.h"
 
int Node::addParentNode(Node *pNode)
{
	// add this node to either leg of parent node, starting from the left
	if (pNode->pLeftChild == NULL) 
	{
		pNode->pLeftChild = this;
	}
	else if (pNode->pRightChild == NULL) 
	{
		pNode->pRightChild = this;
	}
	else 
	{
		// this should never happen
		return -1;	
	}
 
	// add local frequency to parent's total
	pNode->freqTotal += freqTotal;	
 
	return 0;
}
 
Node::Node(int initialCharCode)
{
	this->freqTotal = 0;
	this->charCode = initialCharCode;
	this->pParent = NULL;
	this->pLeftChild = NULL;
	this->pRightChild = NULL;
}