Re: C Programers

new topic     » goto parent     » topic index » view thread      » older message » newer message

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

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu