void inorder(tree_pointer ptr) { /* inorder treetraversal */ if (ptr){ inorder(ptr->left_child); printf(“%d”, ptr->data); indorder(ptr->right_child); } } Each step of the trace shows the call of inorder, the value in the root, and whether or not the printf function is invoked (Figure 5.17). Since there are 19 nodes in the tree, inorder() is invoked 19 times for the complete traversal. The nodes of figure 5.16 would be output in an inorder as A/B*C*D+E PREORDER TRAVERSAL Visit a node, traverse left, and continue (Program 5.2). When you cannot continue, move right and begin again or move back until you can move right and resume. The nodes of figure 5.16 would be output in preorder as +**/ABCDE POSTORDER TRAVERSAL Visit a node, traverse right, and continue (Program 5.3). When you cannot continue, move left and begin again or move back until you can move left and resume. The nodes of figure 5.16 would be output in postorder as AB/C*D*E+
void inorder(tree_pointer ptr) { /* inorder treetraversal */ if (ptr){ inorder(ptr->left_child); printf(“%d”, ptr->data); indorder(ptr->right_child); } } Each step of the trace shows the call of inorder, the value in the root, and whether or not the printf function is invoked (Figure 5.17). Since there are 19 nodes in the tree, inorder() is invoked 19 times for the complete traversal. The nodes of figure 5.16 would be output in an inorder as A/B*C*D+E PREORDER TRAVERSAL Visit a node, traverse left, and continue (Program 5.2). When you cannot continue, move right and begin again or move back until you can move right and resume. The nodes of figure 5.16 would be output in preorder as +**/ABCDE POSTORDER TRAVERSAL Visit a node, traverse right, and continue (Program 5.3). When you cannot continue, move left and begin again or move back until you can move left and resume. The nodes of figure 5.16 would be output in postorder as AB/C*D*E+