public List<Integer> postorderTraversalA(TreeNode root){
  List<Integer> res=new ArrayList<Integer>();
  if (root == null)   return res;
  Stack<TreeNode> s=new Stack<TreeNode>();
  s.push(root);
  while (!s.isEmpty()) {
    TreeNode curNode=s.pop();
    res.add(curNode.val);
    if (curNode.left != null)     s.push(curNode.left);
    if (curNode.right != null)     s.push(curNode.right);
  }
  Collections.reverse(res);
  return res;
}

public List < Integer > postorderTraversalA ( TreeNode root ) { List < Integer > res = new ArrayList < Integer > ( ) ; if ( root == null ) return res ; Stack < TreeNode > s = new Stack < TreeNode > ( ) ; s . push ( root ) ; while ( ! s . isEmpty ( ) ) { TreeNode curNode = s . pop ( ) ; res . add ( curNode . val ) ; if ( curNode . left != null ) s . push ( curNode . left ) ; if ( curNode . right != null ) s . push ( curNode . right ) ; } Collections . reverse ( res ) ; return res ; }
post order : left - right - root modify pre order : root - left - right to root - right - left reverse the result
