Thread: Bst

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    84

    Bst

    How would a level order tranverse go for this BST?

    G
    / \
    C H
    / \ \
    B E I
    / / \ \
    A D F L
    /
    J
    \
    K

    Preorder: G,C,B,A,E,D,F,H,I,L,J,K
    PostorderA,B,D,F,E,C,K,J,L,I,H,G
    Levelorder: ?

  2. #2
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    Does this belong on the game forum? Also... stick your ascii graphics in code tags so we can tell what they're supposed to be
    Away.

  3. #3
    root
    Join Date
    Sep 2003
    Posts
    232
    Here's some psuo...pseoo...soo...uh...fake code*.
    Code:
    levelorderAux(tree, level)
    begin
      if tree is null, return;
      if level is 1, then
        print(tree.root);
      else if level greater than 1, then
        levelorderAux(tree.left_subtree, level-1);
        levelorderAux(tree.right_subtree, level-1);
      endif
    end
    
    levelorder(tree)
    begin
      for d = 1 to height(tree)
        levelorderAux(tree, d);
      endfor
    end
    * Neatly pinched from http://www.nist.gov/dads/ when nobody was looking. That was a real win, it saved me from having to actually type it in from memory. Horrors.
    The information given in this message is known to work on FreeBSD 4.8 STABLE.
    *The above statement is false if I was too lazy to test it.*
    Please take note that I am not a technical writer, nor do I care to become one.
    If someone finds a mistake, gleaming error or typo, do me a favor...bite me.
    Don't assume that I'm ever entirely serious or entirely joking.

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