C++ Program to develop a Huffman Tree
- État: Closed
- Prix: $25
- Propositions reçues: 2
- Gagnant: iit2009013
Résumé du concours
Write a C++ program to develop a Huffman Tree. First you must prompt the user to enter up to 10 letters (from a to z) and the frequency for each letter (the total sum of the frequencies add up to 100). Then create a node for each letter using a struct called node (you must determine what the data types are).
Struct node {
to be implemented………….
}
Insert the nodes of each character into a MinHeap (in class we defined the class MaxHeap, thus use the same class but make sure you change the inequalities from ≤ to ≥ or vice versa) where minimality is with respect to the frequency. The heap is an array of nodes.
1) Delete the first 2 nodes from the heap (using the delete function of the heap class) and create another node where the frequency of the node is the sum of the frequencies of the deleted nodes.
Set address of the new node as the address determined by the new operator.
Add the address of the father node to the deleted nodes. Also set child = ‘L’ for the first deleted node and “R” to the second deleted node.
Repeat step 1) until the heap is empty (remember at the end the final node must have frequency equals to100 and this node is the Huffman tree).
Thus the final Huffman tree looks like the tree in Fig 1.
To determine the code for each letter, starting at the node corresponding to a letter, trace back to the root, and if a node is the leftchild of another node add a 0 to the code and add a 1 otherwise (in reverse order), and go to the father node until the root is reached.
I have attached project details for your reference.
Compétences recommandées
Tableau de clarification publique
Comment commencez des concours
-
Publiez votre concours Rapide et facile
-
Obtenez des tonnes de propositions De partout dans le monde
-
Attribuez la meilleure proposition Télécharger les fichiers - Facile !