Question
I'm trying to make a code that will take in characters and their frequencies in a huffman tree. I'm trying to modify the huffman.h funcitons
I'm trying to make a code that will take in characters and their frequencies in a huffman tree. I'm trying to modify the huffman.h funcitons the be able to take any value that is chosen in the main. Here is the chart of the frequencies that are chosen for the particular assignment.
huffman.h:
#ifndef HUFFMAN_H_INCLUDED
#define HUFFMAN_H_INCLUDED
#include
#include
#include
#include
#include "huffnode.h"
using namespace std;
class huffman
{
public:
huffman();
void buildTree(const string& characters, const vector
void generateCodes();
void listCodes();
void writeTree();
string Compress(string str);
string Decompress(string bits);
private:
int numChars;
int numLeaves;
int treeSize;
//Huffman tree is stored in a vector of huffNode's
vector
//Vector holding the locations of the characters (leaf nodes) in the Huffman tree
vector
//String of characters used to generate the Huffman tree
string characters;
//Corresponding frequencies for the characters
vector
};
huffman::huffman()
{
numChars = 0;
numLeaves = 0;
treeSize = 0;
charLoc.resize(256);
}
void huffman::buildTree(const string& chars, const vector
{
//priority queue used to build Huffman tree
priority_queue
}
void huffman::generateCodes()
{
}
void huffman::listCodes()
{
}
void huffman::writeTree()
{
}
string huffman::Compress(string str)
{
}
string huffman::Decompress(string bits)
{
}
#endif // HUFFMAN_H_INCLUDED
huffnode.h:
#ifndef HUFFNODE_H_INCLUDED
#define HUFFNODE_H_INCLUDED
#include
using namespace std;
//NIL represents empty subtree
const short NIL = -1;
class huffNode
{
public:
unsigned char ch;
short left, right;
int freq;
int index;
int parent;
int numBits;
string bitCode;
huffNode();
friend bool operator> (huffNode lhs, huffNode rhs);
};
huffNode::huffNode()
{
ch = 0;
left = NIL;
right = NIL;
freq = 0;
index = 0;
parent = 0;
numBits = 0;
bitCode = "";
}
bool operator>(huffNode lhs, huffNode rhs)
{
return lhs.freq > rhs.freq;
}
#endif // HUFFNODE_H_INCLUDED
main:
#include "huffnode.h"
#include "huffman.h"
using namespace std;
int main()
{
string characters;
vector
characters = "etaoinsrhldcu";
charFreq = {125,93,80,76,73,71,65,61,55,41,40,31,27};
huffman huff1;
huff1.buildTree(characters, charFreq);
huff1.generateCodes();
huff1.listCodes();
huff1.writeTree();
string charStr, bitCode;
charStr = "end";
//bitCode = huff1.Compress(charStr);
cout
cout
bitCode = "100010101010101000";
//charStr = huff1.Decompress(bitCode);
cout
cout
//Keep Console window open until keyboard input
int hold;
cin >> hold;
}
Huffman Tree Index ch freq left right parent numBits bitCode a26-1-1 000010 b 139-1-1 0010 10 00000 00110 11 00111 f 121-1-1 0001 35-1-1 000011 15 1999-1-1 16 12 224 10 14 14 549 12 13 15 16 3547 15 el 001 d0001110 0010 100 C00000001 t000000001 m64555462-00000000 560234456 g-1111111169451178 f-111111110231114 87 q9 99 3645944 e632882599-0822455 489 39161123513 cabcdefgmy 0123456 H0-234567891Step 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