Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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_2

Step: 3

blur-text-image_3

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

Expert Oracle9i Database Administration

Authors: Sam R. Alapati

1st Edition

1590590228, 978-1590590225

More Books

Students also viewed these Databases questions

Question

Compute the derivative f(x)=(x-a)(x-b)

Answered: 1 week ago

Question

Explain the function and purpose of the Job Level Table.

Answered: 1 week ago