What is the sequence for inorder, preorder, postorder for

----------------------A---------------------------
---------------------/--\--------------------------
--------------------B---C-------------------------
-------------------/-\--/-\------------------------
------------------D-E-F-------------------------
----------------/-\-/-\---------------------------
----------------G-----H--------------------------

Is it correct for

Inorder:GDBHEAFC
Preorder:ABDGEHCF
Postorder:GDHEBFCA

if someone out there can help that will be awesome.

Recommended Answers

All 3 Replies

I highly recommend formatting your tree in a text editor set to a monospace font. I'm assuming this is the tree you wanted:

A
             /   \
           B       C
          / \     /
         D   E   F
        /     \
       G       H

Normally when people ask "is this right" questions, I reply with "test it and find out". The code to write a simple binary tree and test the traversals is very simple. However, I will say that you're on the right track. ;)

The code to write a simple binary tree and test the traversals is very simple.

Yes they are, in Narue' s twisted mind anyway ;)

preorder = visit node, left, right
inorder = left, visit, right
postorder = left, right, visit

Repeat the process at each node.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.