function postOrder(node) { if (!(node == null)) { postOrder(node.left); postOrder(node.right); console.log(node.show() + " "); } } // 给BST类添加该成员方法 function BST() { this.root = null; this.insert = insert; this.preOrder = preOrder; this.inOrder = inOrder; this.postOrder = postOrder; }
后序遍历的打印顺序
按上图的输出顺序是:2 -> 8 -> 9 -> 9 -> 4 -> 3 -> 13 -> 21 -> 18 -> 10