算法比较简单,没有采用递归,javascript实现如下,可以轻易转为其他语言 var stack = new Array();
var scanned = false;
var temp = root;
while (temp) {
stack.push(temp);
if(!scanned&&temp.firstChild){
temp = temp.firstChild;
continue;
}
if(temp.nextSibling){
temp = temp.nextSibling;
scanned = false;
continue;
}
scanned = true;
temp = temp.parentNode;
}
posted on 2012-07-18 21:34
zhanghu198901 阅读(724)
评论(0) 编辑 收藏