算法比較簡單,沒有采用遞歸,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 閱讀(726)
評論(0) 編輯 收藏