1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
klio [65]
3 years ago
10

Please help me with my assigment

Computers and Technology
1 answer:
Art [367]3 years ago
8 0

Answer:

#include <iostream>

#include <queue>

using namespace std;

class HeapNode_Min  

{  

public:

char d;

unsigned f;

HeapNode_Min* l;

HeapNode_Min* r;

HeapNode_Min(char d, unsigned f)

{

 this->l = this->r = NULL;

 this->d = d;

 this->f = f;

}

};

class Analyze {  

public:

bool operator()(HeapNode_Min* l, HeapNode_Min* r)

{

 return (l->f > r->f);

}

};

void display_Codes(HeapNode_Min* root, string s)

{

if (!root)

 return;

if (root->d != '$')

 cout << root->d << "\t: " << s << "\n";

display_Codes(root->l, s + "0");

display_Codes(root->r, s + "1");

}

void HCodes(char data[], int freq[], int s) // builds a Huffman Tree

{

HeapNode_Min* t, *r, *l; // top, right, left

priority_queue<HeapNode_Min*, vector<HeapNode_Min*>, Analyze> H_min;

int a = 0;

while (a < s) {

 H_min.push(new HeapNode_Min(data[a], freq[a]));

 a++;

}

while (H_min.size() != 1)  

{

 l = H_min.top();  

 H_min.pop();

 r = H_min.top();  

 H_min.pop();

 t = new HeapNode_Min('$', r->f + l->f);

 t->r = r;  

 t->l = l;

 H_min.push(t);

}

display_Codes(H_min.top(), "");

}

int main()

{

int frequency[] = { 3, 6, 11, 14, 18, 25 };  

char alphabet[] = { 'A', 'L', 'O', 'R', 'T', 'Y' };

int size_of = sizeof(alphabet) / sizeof(char); //Complete this statement by passing data type to both sizeof operators

cout << "Alphabet" << ":" << "Huffman Code\n";

cout << "--------------------------------\n";

HCodes(alphabet, frequency, size_of);  

return 0;

}

Explanation:

The expected output is:

Alphabet:Huffman Code

--------------------------------

R       : 00

T       : 01

A       : 1000

L       : 1001

O       : 101

Y       : 11

You might be interested in
You told your sister about creating bullet points with Word 2013. She calls you and says that she created a list of six bullet p
lapo4ka [179]

Answer:

Tell her to hold the Shift key as she hits Enter.

8 0
3 years ago
In 1839, Talbot released the paper-based process which he called _ to the public.
vlabodo [156]

Answer:

I'm pretty sure it's photogenic drawing.

7 0
2 years ago
Explain the difference between true north and magnetic north.
Furkat [3]
Magnetic north is the north a compass points in the direction of. True north, on the other hand, is north based on the earth's axis.
4 0
3 years ago
____ is a philosophy and a software and system development methodology that focuses on the development, use, and reuse of small,
LiRa [457]

Answer:

d.) Service-Oriented Architecture

Explanation:

Because its definition matches

4 0
3 years ago
What is the fifth and final stage in the process of media production?
Monica [59]

Answer:54

Explanation:

8 0
3 years ago
Other questions:
  • A computer has 9850 processes and 172 of them where suspended while 276 were terminated.,explain why some of the processes where
    15·1 answer
  • When someone registers a domain name that is a company's trademark, hoping to resell it to the company at an exorbitant profit,
    14·2 answers
  • Technologies have advanced to allow computer chips to be placed in almost anything and to be connected to a network almost anywh
    8·1 answer
  • Who invented the machine known as colossus?
    9·2 answers
  • The largest type of computer system with the most extensive storage capacity and the fastest processing speeds is a ________.
    7·1 answer
  • How many questions have you seen so far other than this one?
    10·2 answers
  • 2) A simple operating system supports only a single directory but allows it to have arbitrarily many files with arbitrarily long
    7·1 answer
  • Pick the correct characteristics that define the porous inkjet paper.
    6·1 answer
  • With
    10·2 answers
  • Which privacy protection uses four colors to indicate the expected sharing limitations that are to be applied by recipients of t
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!