Re: C Programers
- Posted by don cole <doncole at ?acbell.ne?> Jul 23, 2007
- 520 views
CChris wrote: > > 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: > }}} <eucode> > 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 > </eucode> {{{ > > Not the most efficient, but the closest to a verbatim translation. > > CChris Hello CChris, Thank you for your response. My understanding is, and I might be wrong, that a list_node signifies the end of a list item or a line of text. In Euphoria a believe that this is normally character 13. A null node signifies the end of the list normally -1 in Euphoria. I got this from here. http://www-128.ibm.com/developerworks/linux/library/l-recurs.html Maybe if you read this you would understand it better than I. Also to Bernie Ryan thank you for your response Don Cole