I needed to print out the left and right child pointer but I dont know how could someone help?
This is a discussion on question on binary tree within the C Programming forums, part of the General Programming Boards category; I needed to print out the left and right child pointer but I dont know how could someone help?...
I needed to print out the left and right child pointer but I dont know how could someone help?
Your question could be interpreted several ways. Do you want to just print the value of the pointers?
Or do you want to print the contents of each node?Code:printf("%p -- %p\n", (void *)root->left, (void *)root->right);
Or do you really want an inorder traversal?Code:if (node->left != NULL) visit(root->left); if (node->right != NULL) visit(root->right);
It's best to be as detailed as possible when asking a question. That way you can get an answer as quickly as possible.Code:void traverse(node *root, void (*action)(node *p)) { if (root == NULL) return; traverse(root->left, action); action(root); traverse(root->right, action); }![]()
My best code is written with the delete key.