F
fighterman19
I have 2 singly linked list that contain 1 digit in each node like
this
A [ 1 ]--->[ 2 ]--->[ 3 ]---> NULL
B [ 8 ]---> [ 9 ]--->NULL
I want to add A+B ( 123 + 89) and the sum store in another linked list
sum [ 9 ]---> [ 1 ]---->[ 4 ]---->NULL
all i do are
int carry=0;
do{
int sum =0;
sum= A->value + B->value + carry;
if (sum > 9)
{
carry= sum/10;
sum->value=sum%10;
}
else
{
carry=0;
sum->value=sum%10;
}
// how to move form the first node to second node?
} while (A->next != NULL || B->next !=NULL);
can someone to me how to shift in this one? Thank
this
A [ 1 ]--->[ 2 ]--->[ 3 ]---> NULL
B [ 8 ]---> [ 9 ]--->NULL
I want to add A+B ( 123 + 89) and the sum store in another linked list
sum [ 9 ]---> [ 1 ]---->[ 4 ]---->NULL
all i do are
int carry=0;
do{
int sum =0;
sum= A->value + B->value + carry;
if (sum > 9)
{
carry= sum/10;
sum->value=sum%10;
}
else
{
carry=0;
sum->value=sum%10;
}
// how to move form the first node to second node?
} while (A->next != NULL || B->next !=NULL);
can someone to me how to shift in this one? Thank