Home > Software engineering >  Could you tell me how to traverse the tree brothers representation (children) to find a specified no
Could you tell me how to traverse the tree brothers representation (children) to find a specified no

Time:10-04

Such as node structure for struct CSnode {cstrings STR. CSnode * firstchild; CSnode * nextsibling} CSnode; Now the tree he was trying to find the STR for "abcd" node, I want to write this function: CSnode * FindStr searches (CSnode p) {if (p - & gt; STR=="abcd") return p; FindStr searches (p - & gt; Firstchild); FindStr searches (p - & gt; Nextsibling); } always feel wrong feeling, have the master can help me to look at the problem of this code? And I hope to find the first after the abcd exit function, because all of the string is not may have the same situation, in order to save time, so I hope to find out immediately after the first, don't perform this function to a waste of time,

CodePudding user response:

What are you going to use iterate through traversal methods? After the first order, then find out
  • Related