Beispiel #1
0
void HuffmanTree::decode( stringstream & ss, BinaryFileReader & bfile )
{
	TreeNode * current = root;

	while( bfile.hasBits() )
	{
		/**
		 * @todo Your code here!
		 *
		 * This code is reading in all of the bits in the binary file
		 * given. After reading a bit, we go left if the bit was a 0 (or
		 * false), and we go right if the bit was a 1 (or true).
		 *
		 * Special case: if we are at a leaf node, we should "print" its
		 * character to the stringstream (with operator<<, just like cout)
		 * and start traversing from the root node again.
		 */
	
		if( bfile.getNextBit() )
		{
			current = current->right;
		}
		else
		{
			current = current->left;
		}

		if( (current->left == NULL)&&(current->right == NULL) )
		{
			ss << (current->freq).getCharacter();
			current = root;
		}
		
	}
}
Beispiel #2
0
void HuffmanTree::decode( stringstream & ss, BinaryFileReader & bfile ) {
	TreeNode * current = root;
	while( bfile.hasBits() ) {
		if (bfile.getNextBit()) {
			current = current->right;
		}
		else {
			current = current->left;
		}
		if (current->right == NULL && current->left == NULL) {
			ss << current->freq.getCharacter();
			current = root;
		}
	}
}