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;
}
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;
}