Thread: question on binary tree

  1. #1
    Registered User
    Join Date
    Oct 2004

    Lightbulb question on binary tree

    I needed to print out the left and right child pointer but I dont know how could someone help?

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Your question could be interpreted several ways. Do you want to just print the value of the pointers?
    printf("%p -- %p\n", (void *)root->left, (void *)root->right);
    Or do you want to print the contents of each node?
    if (node->left != NULL)
    if (node->right != NULL)
    Or do you really want an inorder traversal?
    void traverse(node *root, void (*action)(node *p))
      if (root == NULL)
      traverse(root->left, action);
      traverse(root->right, action);
    It's best to be as detailed as possible when asking a question. That way you can get an answer as quickly as possible.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Interpreter.c
    By moussa in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 05:59 PM
  2. best STL method to implement a binary tree
    By MatthewDoucette in forum C++ Programming
    Replies: 8
    Last Post: 06-16-2006, 07:08 AM
  3. BST (Binary search tree)
    By praethorian in forum C++ Programming
    Replies: 3
    Last Post: 11-13-2005, 09:11 AM
  4. Templated Binary Tree... dear god...
    By Nakeerb in forum C++ Programming
    Replies: 15
    Last Post: 01-17-2003, 02:24 AM
  5. inserting characters into a binary tree
    By sballew in forum C Programming
    Replies: 4
    Last Post: 12-06-2001, 04:08 PM