static Node head1, head2;
public static void Main()
head1.next = new Node(5);
head1.next.next = new Node(9);
head1.next.next.next = new Node(4);
head1.next.next.next.next = new Node(6);
Console.WriteLine("First List is ");
head2.next = new Node(4);
Console.WriteLine("Second List is ");
Node rs = addTwoLists(head1, head2);
Console.WriteLine("Resultant List is ");
static Node addTwoLists(Node first, Node second) {
while (first != null || second != null)
sum = carry + (first != null ? first.data : 0)
+ (second != null ? second.data : 0);
carry = (sum >= 10) ? 1 : 0;
temp.next = new Node(carry);
static void printList(Node head) {
Console.Write(head.data + " ");