www.vustudents.ning.com

We non-commercial site working hard since 2009 to facilitate learning Read More. We can't keep up without your support. Donate.

# CS301 Assignment No 03 Fall 2019 Solution & Discussion Due Date: 21-01-2020

CS301 Assignment No 03 Fall 2019 Solution & Discussion Due Date: 21-01-2020

Views: 1863

### Replies to This Discussion

CS301 Data Structures Assignment 3 Solution & Discussion Fall 2019

Another Solution idea:

`#include <bits/stdc++.h> using namespace std; class HeapNode_Min { // Tree node of Huffman public://Add data members here. char d;unsigned f;HeapNode_Min *l, *r;HeapNode_Min(char d, unsigned f = -1) { //Complete the body of HeapNode_Min functionthis->d = d;this->f = f ;this->l = NULL;this->r = NULL;} }; class Analyze { // two heap nodes comparisonpublic:bool operator()(HeapNode_Min* l, HeapNode_Min* r) { //add return before statement and statement is completed. return (l->f > r->f); //Complete this statement} }; void display_Codes(HeapNode_Min* root, string s) // To print codes of huffman tree from the root. { if (!root) return; if (root->d != '\$') cout  root->d  "\t: "  s  "\n";display_Codes(root->l, s + "0"); display_Codes(root->r, s + "1"); //Complete this statement by passing arguments} void HCodes(char data[], int freq[], int s) // builds a Huffman Tree{ HeapNode_Min *t,*r, *l ; // top, right, leftpriority_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' }; //Complete this statement by passing data type to both sizeof operators int size_of = sizeof(alphabet) / sizeof(*alphabet);cout"Alphabet"":""Huffman Code\n";cout"--------------------------------\n";//Call Huffman_Codes function. HCodes(alphabet, frequency, size_of);return 0; }`

1

2

3

## Latest Activity

7 hours ago
11 hours ago
Hamza( Graphic Designer) and Mehreen Tasneem are now friends
11 hours ago
Minahil khalid left a comment for ☞De Veloper☜♨
14 hours ago
Aijaz khan updated their profile
18 hours ago
Aijaz khan joined + M.Tariq Malik's group

### CS202 Fundamentals of Front End Development

18 hours ago
Ribqa, Muhammad Rizwan Ansari, Muhammad Imran and 3 more joined Virtual University of Pakistan
18 hours ago
18 hours ago