1

So I been working on this TreeNode program and I couldn't figure out how to print the PostOrder and PreOrder. I got the inOrder correct, but couldn't figure out the rest of the code for PreOrder and PostOrder.

Here my code for inOrder for TreeNode:

public static <T> void inOrder(TNode<T> node) {
        if (node.getLeft() != null)
        inOrder(node.getLeft());

    System.out.print(node.getData() + " ");

    if (node.getRight() != null)
        inOrder(node.getRight());

}
Shankha057
  • 1,296
  • 1
  • 20
  • 38
Paco
  • 7
  • 5

1 Answers1

0
preOrder(node) {
  print(node);
  preOrder(node.left);
  preOrder(node.right);
}

postOrder(node) {
  postOrder(node.left);
  postOrder(node.right);
  print(node);  
}
LowKeyEnergy
  • 652
  • 4
  • 11
  • It would help if you explained the code at least a little bit; and also, there is a problem here because your `postOrder` method makes its calls to `preOrder`. – kaya3 Nov 14 '19 at 21:32
  • 2
    This is a basic description of the algorithm. If he doesn't understand it, it's because he slept through his class. – LowKeyEnergy Nov 14 '19 at 21:34
  • @LowKeyEnergy SO isn't for those who were awaking in the classroom but also for them who didn't even have a classroom! it would be better whatever you are posting please give some description about it. – Papai from BEKOAIL Nov 15 '19 at 06:24