{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Data Str &amp; Algorithm HW Solutions 45

# Data Str &amp; Algorithm HW Solutions 45 - new...

This preview shows page 1. Sign up to view the full content.

45 curr++ // Eat the internal node mark. temp->left = converthelp(inlist, curr); temp->right = converthelp(inlist, curr); return temp; } (c) // Use a helper function with a pass-by-reference // variable to indicate current position in the // node list. template <class Elem> GTNode<Elem>* convert(char* inlist) { int curr = 0; return converthelp(inlist, curr); } // As converthelp processes the node list, curr is // incremented appropriately. template <class Elem> GTNode<Elem>* converthelp(char* inlist, int& curr) { if (inlist[curr] == ’)’) { curr++; return NULL; } GTNode<Elem>* temp =
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: new GTNode<Elem>(inlist[curr++]); if (curr == ’)’) { temp->insert_first(NULL); return temp; } temp->insert_first(converthelp(inlist, curr)); while (curr != ’)’) temp->insert_next(converthelp(inlist, curr)); curr++; return temp; } 6.17 The Huffman tree is a full binary tree. To decode, we do not need to know the weights of nodes, only the letter values stored in the leaf nodes. Thus, we can use a coding much like that of Equation 6.2, storing only a bit mark for internal nodes, and a bit mark and letter value for leaf nodes....
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online