Bst

This is a discussion on Bst within the C++ Programming forums, part of the General Programming Boards category; Ah, yes - I see what you mean A real leaf has both left and right NULL pointers Your logic ...

  1. #16
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,689
    Ah, yes - I see what you mean
    A real leaf has both left and right NULL pointers
    Your logic is looking better at the moment then - what results are you getting?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  2. #17
    Registered User
    Join Date
    Sep 2003
    Posts
    133
    I hope i get it right this time:


    Code:
    void BST::shortestPath(node *rt,stack &s,int minHt)
    { 
      if(rt == NULL)
      return;
     
       stack.push(rt); // store node during pre-traversal
    
       // check for whether min ht is reached and the last node is a leaf
       if( (minHt==0) && (rt->left == NULL) && (rt->right == NULL) )
       {s.print(); // print the value of the nodes 
        s.pop();
        return;}
    
       shortestPath(rt->left,s, minHt-1);
       shortestPath(rt->right,s, minHt-1);
       s.pop(); // remove node during post-treversal
     
    }

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BST array
    By Iron_Shortage in forum C Programming
    Replies: 5
    Last Post: 04-20-2009, 03:04 PM
  2. bst in postorder to file algorithm?
    By iunah in forum C Programming
    Replies: 2
    Last Post: 02-01-2009, 05:13 AM
  3. problem inserting into recursive BST
    By nfrandsen in forum C Programming
    Replies: 4
    Last Post: 09-13-2008, 07:03 PM
  4. I would love some input on my BST tree.
    By StevenGarcia in forum C++ Programming
    Replies: 4
    Last Post: 01-15-2007, 12:22 AM
  5. Splitting BST General
    By cpp_is_fun in forum C++ Programming
    Replies: 1
    Last Post: 11-25-2005, 01:02 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21