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,Comp> pq; // using standard priority queue std::vector a; std::vector nodeCounter; Node *root;

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!