In the code below, the nodes of a postorder tree traversal is always printed
I m wondering if there is a way to store these nodes in the postorder sequence in an array
Do i have to do the traversal in a iterative way?
public static void postOrder(TreeNode root) {
if (root != null) {
postOrder(root.left);
postOrder(root.right);
System.out.print(root.item + " ");
} else {
return;
}
}
Just pass a List along with that method. Untested pseudo-ish code: