Data Structures & Alogs HW_Part_12

Data Structures & Alogs HW_Part_12 - 45 curr Eat...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
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, if (inlist[curr] == ’)’) { curr++; return NULL; } GTNode<Elem>* temp = 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.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
7 Internal Sorting 7.1 Base Case : For the list of one element, the double loop is not executed and the list is not processed. Thus, the list of one element remains unaltered and is sorted. Induction Hypothesis : Assume that the list of n elements is sorted correctly by Insertion Sort. Induction Step : The list of n +1 elements is processed by f rst sorting the top n elements. By the induction hypothesis, this is done correctly. The f nal pass of the outer for loop will process the last element (call it X ). This is
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 4

Data Structures &amp; Alogs HW_Part_12 - 45 curr Eat...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online