We are here with you hands in hands to facilitate your learning & don't appreciate the idea of copying or replicating solutions. Read More>>

Looking For Something at vustudents.ning.com? Click Here to Search

www.bit.ly/vucodes

+ Link For Assignments, GDBs & Online Quizzes Solution

www.bit.ly/papersvu

+ Link For Past Papers, Solved MCQs, Short Notes & More


Dear Students! Share your Assignments / GDBs / Quizzes files as you receive in your LMS, So it can be discussed/solved timely. Add Discussion

How to Add New Discussion in Study Group ? Step By Step Guide Click Here.

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

+ How to Follow the New Added Discussions at Your Mail Address?

+ How to Join Subject Study Groups & Get Helping Material?

+ How to become Top Reputation, Angels, Intellectual, Featured Members & Moderators?

+ VU Students Reserves The Right to Delete Your Profile, If?


See Your Saved Posts Timeline

Views: 1396

.

+ http://bit.ly/vucodes (Link for Assignments, GDBs & Online Quizzes Solution)

+ http://bit.ly/papersvu (Link for Past Papers, Solved MCQs, Short Notes & More)

+ Click Here to Search (Looking For something at vustudents.ning.com?)

+ Click Here To Join (Our facebook study Group)

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 function
this->d = d;
this->f = f ;
this->l = NULL;
this->r = NULL;
}
};

class Analyze { // two heap nodes comparison

public:
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, 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' };
//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;
}

RSS

Latest Activity

Mani Siddiqui BS VIII posted a status
"میں کسی اور کے خواب اب دیکھوں کیسے تیری تصویر سرہانے جو پڑی رہتی ہے"
1 hour ago
+++A++R+++ posted a status
"رِشتے صِرف اُنہی سے بناو... جو نِبھانے کی اوقات رکھتےہو..."
2 hours ago
+++A++R+++ posted a discussion
2 hours ago
Mani Siddiqui BS VIII posted a status
3 hours ago
Mani Siddiqui BS VIII posted a discussion
3 hours ago
♦_"cнαη∂α"_♦ liked ♦_"cнαη∂α"_♦'s discussion Batch 6th Quiz No.1
3 hours ago
♦_"cнαη∂α"_♦ added a discussion to the group Freelancing DigiSkills Training Program
3 hours ago
+ ! ! ! ! Mobi updated their profile
4 hours ago
Mani Siddiqui BS VIII replied to Mani Siddiqui BS VIII's discussion Allah o Akbar| Pakistan Air Force Song |27 Feb 2020
4 hours ago
Mani Siddiqui BS VIII liked Mani Siddiqui BS VIII's discussion Allah o Akbar| Pakistan Air Force Song |27 Feb 2020
4 hours ago
Ateeqa replied to +Аүмаи+'s discussion ذرا ذرا سے منافق تو سارے ھوتے ہیں
5 hours ago
Ateeqa replied to +ıllıllı $µǥąя ǥ€ɲɨµ$ ıllıllı+'s discussion Coronavirus
5 hours ago

© 2020   Created by + M.Tariq Malik.   Powered by

Promote Us  |  Report an Issue  |  Privacy Policy  |  Terms of Service

.