[R] Break during the recursion?
h.wickham at gmail.com
Sun Jul 15 22:04:12 CEST 2007
On 7/15/07, Atte Tenkanen <attenka at utu.fi> 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].
> if (is.na(v[i])==FALSE & is.null(unlist(v[i]))==FALSE)
> print(v[i]) # return doesn't work here
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)
More information about the R-help