Data Str & Algorithm HW Solutions 44

Data Str & Algorithm HW Solutions 44 - } (b) // Use a...

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

View Full Document Right Arrow Icon
44 Chap. 6 General Trees 6.16 (a) // Use a helper function with a pass-by-reference // variable to indicate current position in the // node list. template <class Elem> BinNode<Elem>* convert(char* inlist) { int curr = 0; return converthelp(inlist, curr); } // As converthelp processes the node list, curr is // incremented appropriately. template <class Elem> BinNode<Elem>* converthelp(char* inlist, if (inlist[curr] == ’/’) { curr++; return NULL; } BinNode<Elem>* temp = new BinNode(inlist[curr++], NULL, NULL); temp->left = converthelp(inlist, curr); temp->right = converthelp(inlist, curr); return temp;
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: } (b) // Use a helper function with a pass-by-reference // variable to indicate current position in the // node list. template <class Elem> BinNode<Elem>* convert(char* inlist) { int curr = 0; return converthelp(inlist, curr); } // As converthelp processes the node list, curr is // incremented appropriately. template <class Elem> BinNode<Elem>* converthelp(char* inlist, int& curr) { if (inlist[curr] == ’/’) { curr++; return NULL; } BinNode<Elem>* temp = new BinNode<Elem>(inlist[curr++], NULL, NULL); if (inlist[curr] == ’\’’) return temp;...
View Full Document

This note was uploaded on 12/27/2011 for the course MAP 2302 taught by Professor Bell,d during the Fall '08 term at UNF.

Ask a homework question - tutors are online