On 7/15/07, Atte Tenkanen <[EMAIL PROTECTED]> wrote:
> Here is now more elegant function for inorder tree walk, but I still can't 
> save the indexes!? This version now prints them ok, but if I use return, I 
> get only the first v[i].
>
> leftchild<-function(i){return(2*i)}
>
> rightchild<-function(i){return(2*i+1)}
>
> iotw<-function(v,i)
>
> {
>         if (is.na(v[i])==FALSE & is.null(unlist(v[i]))==FALSE)
>         {
>                 iotw(v,leftchild(i))
>                 print(v[i]) # return doesn't work here
>                 iotw(v,rightchild(i))
>         }
> }

Shouldn't you return:

c(iotw(v, leftchild(i)), v[i], iotw(v, rightchild(i)))

(and rewrite the conditition to return null if the node doesn't exist,
I think it reads clearer that way)

Hadley

______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to