1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

C++ Help

Discussion in 'C++' started by Castegna, Jun 5, 2007.

  1. Castegna

    Castegna New Member

    Hi my name is Javier, I am Computer science major. I need help with Binary tree operations. I need some help writing a non-recursive c++ function that counts the number of leafs in a tree?? Thanks you
  2. karri

    karri New Member

    i think this code wil help

    nodeptr stack[MAX_SIZE];
    inorder(nodeptr node)
      int i = 0;
        for(;node;node = node -> left)
          add(node);                           // adding node to stack
       node = pop();                         // pop from stack
       if(!node->rchild && !node->lchild)
      node = node->rchild;
     printf("no of leaf nodes = %d",i);
    Basically it is the same as the iterative version of the inorder traversal
    Last edited by a moderator: Jun 6, 2007
  3. DaWei

    DaWei New Member

    Karri, please read the "Before you post a query" thread; specifically, learn to use code tags.
  4. shabbir

    shabbir Administrator Staff Member

    Code formatting

Share This Page