Be the first user to complete this post
|
Add to List |
Add two numbers represented by a linked list, Numbers are Stored in FORWARD order
This post is the extension of - Two numbers represented by a linked list, Number Stored in REVERSE order
Objective: Two numbers represented by a linked listwhere each node contains single digit. The digits are stored in Forward order, means head is pointing to the last digit of the number.
Input: Two numbers represented by Linked Lists
Output: Addition of two numbers represented by a Linked List.
Example:
First Number : 1007 Second Number : 93 Addition : 1100
Approach:
- Get the length of both the lists.
- If lengths are not equal, make them equal by adding nodes with value 0 in front of shorter linked list.
Code:
First Number : ->1->0->0->7 Second Number : ->9->3 Addition : ->1->1->0->0
Also Read: