int add(struct node* pL1, struct node * pl2,int gap/*no of digits in l1 -no of digits in l2*/) { //assumption, # of nodes in L1 is > # of nodes in L2, make sure this before calling this, counting nodes is less costlier than reversal
if (!(pl1) || !(pl2)) return 0; if (gap>0) { carry = add(pL1->next, pL2, gap-1); carry = (pl1->data+carry)/10; pl1->data =(pl1->data+carry) %10; return carry; } else { carry = add(pL1->next, pl2->next, gap -1); carry = (pl1->data+pl2->data+carry)/10; pl1->data =(pl1->data+pl2->data+carry) %10; return carry; } } Best Regards Ashish Goel "Think positive and find fuel in failure" +919985813081 +919966006652 On Sun, Aug 15, 2010 at 12:19 PM, Manjunath Manohar < manjunath.n...@gmail.com> wrote: > @Dave..Can u provide a small snippet for ur explanation pls.. > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algoge...@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.