Tuesday, January 1, 2013

Question 4


Given a Family Tree, (not necessarily a Binary Tree) print the details of all person in order of generation level.

                                         Jim
                                    /              \

                                /                     \

                             /                          \

                          /                                \

                       /                                     \
                  Martha                                Joe
                 /   |  \                                   /      \
            Sally Andrew Stewart       Kimmel   Walsh
            /
         Peter
       /   |   \
    Meg  Chris  Stewie

Note:[ There's no sibling pointer, each node points to its children]

Expected O/p:
Gen 1: Jim
Gen 2: Martha
       Joe
Gen 3: Sally
       Andrew
       Stewart
       Kimmel
       Walsh
Gen 4: Peter
Gen 5: Meg
       Chris
       Stewie

1 comment:

  1. Check out the answer at AnswerToQ4 and let me know your comments to my code.

    ReplyDelete