# Linked List

Two numbers are given in the form of linked list (with each node storing one digit). Write an algorithm which will compute the sum of these two linked lists. The result should be a linked list as below:

Given two linked lists that merge at some point as shown below: Last four nodes are common to both the lists. Given pointers to the header nodes of each list, find the first common node.

Given a multi-level linked list as shown in this post. Write code to search in such a list.

Given a linked list, where each node has a pointer to the head of its child list (in addition to the next pointer). The child list is a normal linked list with each node having one data and one pointer to the next node in the child list. Let the lists be arranged (as above) […]

Given a linked list, write code to print the list in forward and backward order. Solution: This problem is discussed as an example in this post. A linked list is a data structure where address of next node is stored inside each node. Structure of Node Structure of Node of a list is as given […]

Given a linked list, rearrange the node of the list as shown below: INPUT LIST: 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8 OUTPUT: 1 -> 8 -> 2 -> 7 -> 3 -> 6 -> 4 -> 5 INPUT LIST: 1 -> 2 -> 3 -> 4 […]

We have already seen the code to merge two sorted linked list, such that the final list is also sorted. The logic and code can be found in this post. In this post, we want to merge the two lists in a way that in the final list, element comes from the two lists alternately […]

The structure of Node of a Binary Tree and Doubly linked list are same. struct Node { int data; Node* left; Node* right; } Structure of Node of a Binary Tree struct Node { int data; Node* previous; Node* next; } Structure of Node of a Doubly linked list If we treat […]

Given a linked list, write the non-recursive function to reverse the list. If Input list is 1 -> 2 -> 3 -> 4 -> 5 Then output should be 5 -> 4 -> 3 -> 2 -> 1 We have seen the recursive and non-recursive functions to reverse the list. In the non-recursive version, we take three […]

Write a recursive function that add 5 to the alternate nodes of the linked list. For example, if the list is 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8 -> 9 -> 10 then the function should change the list to the below one 1 -> 7 -> […]