Skip to content

Instantly share code, notes, and snippets.

@tsterker
Created November 11, 2011 00:02
Show Gist options
  • Save tsterker/1356688 to your computer and use it in GitHub Desktop.
Save tsterker/1356688 to your computer and use it in GitHub Desktop.
[c] btree traversal
/* btree traversal - most left to most right */
pnode traverse(pnode root, void (*func)(pnode))
{
pnode ret, tmp = root;
if(!root) return root;
while((tmp = traverse(tmp->left, func))){; }
ret = traverse(root->right, func);
func(root); /* function to manipulate node */
return ret;
}
/* minimal - do stuff in between recursive calls*/
pnode traverse(pnode root)
{
if(!root) return root;
traverse(root->right)
traverse(root->left)
return root;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment