does anyone have an idea how the code looks like when traversing a binary tree in euler's tour??
does anyone have an idea how the code looks like when traversing a binary tree in euler's tour??
? I'm confused. Euler tours only exist in connected graphs where each node has an even degree. This isn't the case in most binary trees....
i have read that there's a euler's traversal for binary... the preorder, inorder, and postorder traversals are special cases of the Euler tour traversal. however i really don't know how it traverses a binary tree..
Last edited by devilclaw; 02-02-2008 at 07:27 PM.
Oh ok, well if you're just looking for the different traversals of a binary tree, they can be easily expressed recursively:
You would pass this function a pointer to the root node of your tree. To do preorder and postorder traversals, you just change the order in which you do things.Code:void traverse_in_order(Node * n) { if (n->left_child != NULL) traverse_in_order(n->left_child); printf("%d\n", n->value); if (n->right_child != NULL) traverse_in_order(n->right_child); }
For example, for a preorder traversal, you would first print the value, then do left, and then right child.