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]
4 years ago
10

Please help me with my assigment

Computers and Technology
1 answer:
Art [367]4 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
Which of the following is not a danger of blogging
Ainat [17]
D. staying connected with an old friend.

4 0
3 years ago
Read 2 more answers
Write the code to declare a variable to hold the value of the grade you hope to get in this class. What stdio.h input function w
GREYUIT [131]

Answer:

// code to read grade

#include <stdio.h>

// main function

int main(void) {

   // if grade is character

char grade;

// if grade is numeric then we can use int or double

// int grade;

// double grade;

printf("Enter your grade:");

// read grade from user

scanf("%c",&grade);

// print grade

printf("your grade is:%c",grade);

return 0;

}

Explanation:

To read a value, scanf() function is used from stdio.h.Read a grade from user and assign it to variable "grade".

Output:

Enter your grade:A

your grade is:A

// code to read die volt

#include <stdio.h>

// main function

int main(void) {

// variable

double die_volt;

printf("Enter die volt:");

// read die volt from user

scanf("%lf",&die_volt);

// print die volt

printf("Entered die volt is:%0.2lf",die_volt);

return 0;

}

Explanation:

Read the die volt from user and assign it to variable "die_volt" with the help

of scanf() function.

Output:

Enter die volt:220                                                                                                        

Entered die volt is:220.00

4 0
4 years ago
1. [10 marks] We begin with some mathematics regarding uncountability. Let N = {0, 1, 2, 3, . . .} denote the set of natural num
crimeas [40]

Answer:

Please see attachment

Explanation:

Please see attachment

Download pdf
6 0
4 years ago
HELP!!!
jeyben [28]

Answer:

A. a tool tip

Explanation:

6 0
3 years ago
Read 2 more answers
11. The golden rule of safe driving is: A. Always drive at the posted speed limit B. Never drive while physically or mentally im
Nonamiya [84]

Your correct answer is A. Always drive at the posted speed limit.

While B. and C. are logically also correct, I wouldn't call them the "golden" rules. Following A. can help you avoid B. to make matters better, hehe.

3 0
3 years ago
Other questions:
  • Which of the following should businesses and organizations do to promote a safe work environment?
    6·1 answer
  • Who can effectively use website authoring software?
    6·1 answer
  • Write a method called evenBeforeOdd that accepts an array of integers and rearranges its elements so that all even values appear
    15·1 answer
  • In which of the following situations will a macro make your work more efficient?
    12·1 answer
  • What is contrast (in Photography)?
    14·1 answer
  • Company Wizzy is having trouble with network security. Issues with authentication, viruses, malware/spyware, and other network i
    12·1 answer
  • Hello! I hope you have a great day! Good things will come your way.
    12·1 answer
  • You learned that you can use the tags to insert a link to another webpage. One problem that webpage developers face is that, aft
    7·1 answer
  • Mention three types of pipeline hazards​
    6·2 answers
  • Assume you're using a three button mouse.To access shortcut menus,you would
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!