Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Recursive: See recursive
Message
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
01083365
Message ID:
01083772
Vues:
10
Einar,

What is your terminal condition? Usually trees are traversed in one of two ways:
PreOrderTraverse( oNode )
{
? oNode.Name; // process the node
for each oNode in oNode.Nodes
   PreorderTraverse( oNode );
}


PostOrderTraverse( oNode )
{
for each oNode in oNode.Nodes
   PostOrderTraverse( oNode );
? oNode.Name; // process the node
}
For binary trees the terminal condition is a null pointer. In the case of a sorted binary tree:
InOrderTraverse( oNode )
{
if ( ! isnull( oNode ) )
   {
   InOrderTraverse( oNode.Left );
   ? oNode.Name;
   InOrderTraverse( oNode.Right );
}
The terminal condition though is usually defined by an attribute of the node being processed.

>Rick,
>I don't see how I can accomplish what I want without the bool return value.
>Your example will always recurse through all nodes in the tree (please correct me if I am wrong because I find recursion very mind bogling).
>
>Einar
>
>>And you can even avoid the boolean return value if you want to:
>>
>>
>>
>>private void button2_Click(object sender, System.EventArgs e)
>>{
>>  RecursiveMethod(oTree.Nodes[0]);
>>}
>>
>>private void RecursiveMethod(TreeNode treeNode)
>>{
>>  if(treeNode.Nodes.Count>0)
>>     foreach(TreeNode n in treeNode.Nodes)
>>        RecursiveMethod(n);
>>  else
>>     MessageBox.Show(treeNode.Text);
>>}
>>
>>
df (was a 10 time MVP)

df FoxPro website
FoxPro Wiki site online, editable knowledgebase
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform