CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2009
    Posts
    26

    [RESOLVED] tree traversals

    I have to list to the vertices according to a preorder traversal, an inorder traversal, and a postorder traversal.

    Here's what I have so far:

    preorder: 0,1,3,6,7,9,10,2,4,5,8,11

    inorder: 0,1,2,3,4,5,6,7,8,9,10,11

    postorder: need help on how to do this

    are the first 2 correct?
    Attached Files Attached Files

  2. #2
    Join Date
    Mar 2009
    Posts
    19

    Re: tree traversals

    If you have preorder and inorder, you should be able to do postorder. They're just swapping the orders in which you do things.

    preorder:

    1. visit node
    2. preorder(node.left)
    3. preorder(node.right)

    inorder:

    1. inorder(node.left)
    2. visit node
    3. inorder(node.right)

    postorder:

    1. postorder(node.left)
    2. postorder(node.right)
    3. visit node

    Ignoring the base cases for simplicity, of course.

  3. #3
    Join Date
    Apr 2009
    Posts
    26

    Re: tree traversals

    Okay so did I do the first two correct?

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