Thread: Bst

  1. #16
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    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.

  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
     
    }

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, 06: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, 01:22 AM
  5. Splitting BST General
    By cpp_is_fun in forum C++ Programming
    Replies: 1
    Last Post: 11-25-2005, 02:02 AM