Thread: A binomial queue (binomial tree) question.

  1. #1
    Compiling
    Join Date
    Jun 2003
    Posts
    69

    A binomial queue (binomial tree) question.

    Hello.
    I want to write a function to print all the elment in a binomial tree level by level, that means, first print the element in depth 0 and then depth 1, and so on..
    but I had a problem that there may be no relationship between the nodes which are at the same depth (e.g. the red circle in the picture). So, how could I print them? Plz give me a method, thx a lot!

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Brute force algorithm: In a loop, traverse the entire tree while maintaining your current depth. If you are currently at the "print depth level", print the current node. Once you've traversed the entire tree, increment "print depth level" and do it again. Stop if you traverse the tree without printing anything.

    This can be easily optimized in many different ways. Now do your homework!

    gg

  3. #3
    Compiling
    Join Date
    Jun 2003
    Posts
    69
    thx, but I think I do not fully understand your words, could you give me an explanation of that algorithm?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BST delete again, but this time I think I'm close
    By tms43 in forum C++ Programming
    Replies: 9
    Last Post: 11-05-2006, 06:24 PM
  2. problem in creating a tree
    By Lorin_sz in forum C++ Programming
    Replies: 2
    Last Post: 09-26-2005, 01:28 PM
  3. ADT queue
    By ^xor in forum C Programming
    Replies: 4
    Last Post: 06-15-2005, 05:43 AM
  4. Help: One Question for each: Linked List and Tree
    By Yin in forum C++ Programming
    Replies: 1
    Last Post: 04-14-2002, 12:57 AM
  5. queue question
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 10-02-2001, 05:06 PM