Question
implement a deconstructor for the following code: my current deconstructor is seg faulting on me because im deleting stuff that i dont have.. Using c++!
implement a deconstructor for the following code: my current deconstructor is seg faulting on me because im deleting stuff that i dont have.. Using c++! thanks!
class Node { public: // constructor with left and right NULL nodes Node(char charTemp, int c) { ch = charTemp; count = c; left = NULL; right = NULL; };
// constuctor used while building the tree Node(char charTemp, int c, Node *n1, Node *n2) { ch = charTemp; count = c; left = n1; right = n2; };
~Node() { delete left; delete right; }
int count; // counting the frequency of the character in the string char ch; Node *left; Node *right; };
struct Comp { // compare used while building the minheap bool operator()(const Node *a, const Node *b) { return a->count > b->count; } }; // our class class Huffman {
private: std::priority_queue
void incrementCount(char inc) { // internal function to calculate the frequency of the character in the string for (int i = 0; i < nodeCounter.size(); i++) { if (nodeCounter.at(i) -> ch == inc) { nodeCounter.at(i) -> count++; // incrementing the frequency of the character return; } } }
public: // default constructor Huffman() {
} // deconstructor ~Huffman() { delete root; for (int i = 0; i < nodeCounter.size(); i++) { delete nodeCounter.at(i); } }
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