Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I have everything working except my decompress will not stop running. i think its getting stuck in the loop and I can't find why. Cna
I have everything working except my decompress will not stop running. i think its getting stuck in the loop and I can't find why. Cna someone help please. Its opening the file and reading the data but it wont stop running
Decompress a huffman-compressed file In: _outputFile where to write the uncompressed data to // Note: The mFileName will be the compressed file void Decompress (const char* _outputFile) { TODO : 1. Create a BitIfStream and read the frequency table BitIfstream bis (mFileName. c_str (), (char *)mFrequencyTable, 256 * 4); // 2. create the leaf list and tree (in this order) GenerateLeafList () ; GenerateTree () ; // 3. Create a standard ofstream for output (binary mode) std::ofstream aFile(_outputFile, std: : ios : :out | std: : ios : :binary) ; // 4. Create a bool to use for traversing down the list, and a char to store the character for writing bool trav; char stor ; // 5. Create a node pointer for use in traversing the list (start it at the top) HuffNode* tNode = mRoot; 6. Go through the compressed file one bit at a time, traversing through the tree When you get to a leaf node, write out the value, and go back to the root Note: Remember, there may be trailing 0's at the end of the file, so only loop the appropriate number of times for (size_t i = 0; i left != nullptr && twode->right != nullptr) bis >> trav; if (trav == true) tNode = tNode->right; else tNode = tNode->left; stor = (char )tNode->value; aFile 0) mLeafList. push_back (new HuffNode (i , mFrequencyTable[i])) ;void GenerateTree() { TODO : 1. Create the priority queue This will be storing HuffNode*'s in a vector, and will be using the Huffcompare for comparison std: :priority_queue , HuffCompare > queue; // 2. Add in all data from your leaf list for (size_t i = 0; i freq + second->freq)); parent->left = first; parent ->right = second; first->parent = second->parent = parent; queue. push (parent) ; // 4. Set the root of the tree (this will be the only node in the queue) mRoot = queue. top ()Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started