Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

can someone please help me fix my generate codes i have tried debugging and I just don't understand where I am going wrong with my

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

can someone please help me fix my generate codes i have tried debugging and I just don't understand where I am going wrong with my coding

\#define HFFMAN_DEBUG_DECOMPRESS // Wraps up Huffman compression algorithm class Huffman \{ friend class UnitTests_Lab8; // Giving access to test code // A node for a a Huffman tree struct HuffNode \{ short value; unsigned int freq; HuffNode* left; HuffNode* right; HuffNode* parent; HuffNode(short _value, unsigned int_freq, HuffNode*_left = nullptr, HuffNode*_right = nullptr, HuffNode* _parent = nullptr) : value(_value), freq(_freq), left(_left), right(_right), parent(_parent) \{ \} HuffNode(const HuffNode\&_hnode) : value(_hnode.value), freq(_hnode.freq), left(_hnode.left), right(_hnode.right), parent(_hnode.parent) \{ \} \}; struct HuffCompare \{ bool operator() (const HuffNode* _a, const HuffNode* _b) \{ return (_a->freq > _b->freq); \} ; ; // Data members // NOTE: Values set to 1/1 for unit test purposes std: :string mFileName = "-1"; unsigned int mFrequencyTable[256] ={1}; std: : vector mLeafList; HuffNode* mRoot = reinterpret_cast HuffNode >(1); std: : vector mEncodingTable [256]; std: : vector mEncodingTable [256]; Huffman(const std: :string\& _fileName) \{ // TODO: Implement this method mFileName = _fileName; mRoot = nullptr; for (size_t i=0;i freq + node2 > freq, node1, node2); nodel parent = parent; node2 > parent = parent; genrTree . push(parent); \} mRoot = genrTree top(); \} void GenerateEncodingTable() \{ // TODO: Implement this method HuffNode* temp = nullptr; for (size_t i=0;iparent ! = nullptr) \{ if ( temp > parent left == temp ) \{ mEncodingTable[mLeafList[i]->value] .push_back (); \} else if (temp->parent right == temp) \{ mEncodingTable[mLeafList[i] ->value] .push_back(1); \} temp = temp->parent; \} reverse (mEncodingTable [mLeafList[i]->value] . begin(), mEncodingTable [mLeafList [i] value ]. end()); \} \} void ClearTree() \{ // TODO: Implement this method ClearTree(mRoot); mRoot = nullptr ; mRoot = nullptr ; \} void ClearTree (HuffNode*_curr) \{ // TODO: Implement this method if (_curr == nullptr) \{ return; \} ClearTree (_curr left) ; ClearTree (_curr right); delete_curr; j void Compress(const char* _outputFile) \{ // TODO: Implement this method std: : ofstream compFile(_outputFile, std::ios::binary); if (! compFile.is_open()) \{ return; \} for (size_t i=0;i (fileChar ); std : : vector encodeBits = mEncodingTable [compChar ]; for (bool bit : encodeBits) \{ bufferBit.push_back(bit); while (bufferBit.size() >= 0) \{ unsigned char byte =0; for (size_t i=0;i ) \{ unsigned char byte =0; for (size_t i=0;i right ; \} else \{ currNdoe = currNdoe > left ; \} if (currNdoe left == nullptr && currNdoe->right == nullptr) \{ compFile.write(reinterpret_cast (\&currNdoe->value), sizeof(short)); currNdoe = mRoot; bytRead ++ ; if (bytRead == fileSize) \{ hraak: if (bytRead == fileSize) \{ break; \} \} \} \} file.close(); compFile.close(); \}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application Development And Administration

Authors: Michael V. Mannino

3rd Edition

0071107010, 978-0071107013

More Books

Students also viewed these Databases questions