http://www.cnblogs.com/webFro...
上面这篇文章中的先序排列的非递归算法如下:
BinaryTree.prototype.preOrder_stack = function (visit) {
var stack = new Stack();
stack.push(this);
while (stack.top) {
var p;
// 向左走到尽头
while ((p = stack.peek())) {
p.data && visit(p.data);
stack.push(p.leftChild);
}
stack.pop();
if (stack.top) {
p = stack.pop();
stack.push(p.rightChild);
}
}
};
var stack = new Stack();
这句是什么意思啊?Stack对象没有定义啊!难道是内置对象?
stack.top也不懂……
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…