Node * addlist(int carry,Node *first, Node *second)
{
if(first == NULL && second == NULL)
return NULL;
struct Node *res = createNode(0);
int value=carry;
value+=(first->data+second->data);
struct Node *more = addlist( value/10,first!=NULL ? first->next:NULL,second!=NULL ? second->next:NULL);
if(more == NULL && value>=10)
{// in the top of this stack a null will return;this is only run on the second layer of the function stack
Node *newTail = createNode(0);
newTail->data = 1;
newTail->next = NULL;
res->next = newTail;
}
else
{
res->next = more;
//return res;
}
res->data = value%10;
return res;// this value is return for the next stack
}
{
if(first == NULL && second == NULL)
return NULL;
struct Node *res = createNode(0);
int value=carry;
value+=(first->data+second->data);
struct Node *more = addlist( value/10,first!=NULL ? first->next:NULL,second!=NULL ? second->next:NULL);
if(more == NULL && value>=10)
{// in the top of this stack a null will return;this is only run on the second layer of the function stack
Node *newTail = createNode(0);
newTail->data = 1;
newTail->next = NULL;
res->next = newTail;
}
else
{
res->next = more;
//return res;
}
res->data = value%10;
return res;// this value is return for the next stack
}