Return NSString from a recursive function

Posted by Dave on Stack Overflow See other posts from Stack Overflow or by Dave
Published on 2010-05-29T14:41:06Z Indexed on 2010/05/29 14:42 UTC
Read the original article Hit count: 158

Filed under:
|

Hi,

I have a recursive function that is designed to take parse a tree and store all the values of the tree nodes in an NSString.

Is the algorithm below correct?

NSString* finalString = [self parseTree:rootNode string:@""];

-(NSString*)parseTree:(Node*)currentNode string:(NSMutableString*)myString
{
    [myString appendText:currentNode.value];

    for(int i=0;i<[currentNode.children length];i++){
        return [self parseTree:[currentNode.children] objectAtIndex:i] string:myString];
    }
}

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about recursion