C语言遍历二叉树
树结构体
struct tree_node { tree_node *left; // left subtree has smaller elements tree_node *right; // right subtree has larger elements int data; };
从左到右打印树节点
void print_inorder(tree_node *p) { if (p != NULL) { print_inorder(p->left); // print left subtree cout << p->data << endl; // print this node print_inorder(p->right); // print right subtree } }