CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Traversing this

  1. #1
    Join Date
    May 2003
    Posts
    347

    Traversing this

    Hello All,

    I have a tree, like shown in the bitmap, att. I want to traverse all the paths and print it. Can you pls write me the a reccurssive function for this.

    For the tree I have given , o/p should be

    A1B1C1D1
    A1B1C1D2
    A1B1C1D3
    A1B1C2


    Thanks
    Attached Images Attached Images  

  2. #2
    Join Date
    Oct 2002
    Location
    Singapore
    Posts
    3,128
    How about showing what you have done?

  3. #3
    Join Date
    May 2003
    Posts
    347
    Sorry,

    Am not getting any idea how to go abt on this.

  4. #4
    Join Date
    Feb 2000
    Location
    Indore, India
    Posts
    1,046
    Hello spicy_kid2000,

    If you are using MFC, using CListCtrl to represent your tree visually and using its function SetItemData & GetItemData to set and retrieve the data will be very helpful.

    Regards.
    Pravin.
    27-01-2004.

  5. #5
    Join Date
    Oct 2002
    Location
    Singapore
    Posts
    3,128
    Here's the rough idea.

    First, you can create a class/structure for each node and it should keep a list of its children node. If the list is empty, it can be used to indicate a leave node.

    For the traversing part, you can start by passing the first node into recursive function. The function checks if the list is not empty and loop through each node and calling the same function. The function should only return when it reaches the leave node.

    You may also like to pass another parameter, which keep track of the list of nodes you have already traverse, into the recursive function. Just before returning from the recursive function, you can print out the result.

    Hope this helps.

  6. #6
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    [Merged threads]


    spicy_kid2000, please do not cross-post your questions to different forums. Thank you very much.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured