Re: C Programers
- Posted by CChris <christian.cuvier at ?gri?ulture.gouv.fr> Jul 22, 2007
- 518 views
don cole wrote: > > Hello C Programers, > > Can any of you translate this to Euphoria? > > int sum_list(struct list_node *l) > { > if(l == NULL) > return 0; > return l.data + sum_list(l.next); > } > > Don Cole What is the definition of list_node? Obviously it's a structure that has fields named data and next, but that's a little short. My guess is that you have to translate a linked list of nodes into a sequence of nodes. Then you'd only need to do this:
function sum_list_(integer sum,integer index,sequence nodes) if index<=length(nodes) then return sum_list_(sum+nodes[index][DATA],index+1,nodes) else return sum end if end function function sum_list(sequence nodes) return sum_list_(0,1,nodes) end function
Not the most efficient, but the closest to a verbatim translation. CChris