随笔-31  评论-14  文章-0  trackbacks-0
 算法比较简单,没有采用递归,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 阅读(716) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: