This week's book giveaway is in the Testing forum.We're giving away four copies of Data Structures the Fun Way: An Amusing Adventure with Coffee-Filled Examples and have Jeremy Kubica on-line!See this thread for details.
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Liutauras Vilda
• Tim Cooke
• Jeanne Boyarsky
• Paul Clapham
Sheriffs:
• Devaka Cooray
• Ron McLeod
• paul wheaton
Saloon Keepers:
• Tim Moores
• Piet Souris
• Tim Holloway
• Stephan van Hulst
• Carey Brown
Bartenders:
• Al Hobbs
• Frits Walraven
• Scott Selikoff

# traversing a simple tree in js.

Ranch Hand
Posts: 1209
• Number of slices to send:
Optional 'thank-you' note:
i think a pair of fresh eyes would help me here.
Does the following result in an infinite loop (processNode)
It does..how do i fix this?

<html>
<script>
//Construct a tree
function TreeNode(strText) {
this.childNodes = new Array();
this.text = strText
return this;
}

var objNode = new TreeNode(strText);
this.childNodes[this.childNodes.length] = objNode;
return objNode;
}

var localTree = new TreeNode("root");

processNode(localTree);

function processNode(node) {
for(i=0; i < node.childNodes.length; i++){
processNode(node.childNodes[i]);
}
}

</script>
</html>

Karthik Guru
Ranch Hand
Posts: 1209
• Number of slices to send:
Optional 'thank-you' note:
Any help? I cant understand how this can result in infinite recursion.
Is somethign wrong with my class definition? (Node and addChild).

 I have gone to look for myself. If I should return before I get back, keep me here with this tiny ad: the value of filler advertising in 2021 https://coderanch.com/t/730886/filler-advertising