
Assignment
1. Given a singly linked list, write a function to swap elements pairwise.
Eg: 1 2 3 4 5 6 7 8 //Before
2 14 3 6 5 8 7 //After
2. Given two linked lists, insert nodes of second list into first list at alternate positions of first list.
Eg: First list is 57171311 and
Second is 1210246,
The resultant list should become 512710172134116
3. Given a linked list and two integers M and N. Perform the following:
Eg : M = 2, N = 2
Linked List: 1->2->3->4->5->6->7->8
Output:
Linked List: 1->2->5->6
4. Given two numbers represented by two linked lists, write a function that returns sum list.
First List: 5->6->3 // represents number 563
Second List: 8->4->2 // represents number 842
Output
Resultant list: 1->4->0->5 // represents number 1405
5. Given a singly linked list, rotate the linked list counter-clockwise by k nodes. Where k is a given
positive integer.
Eg: Given linked list is
102030405060 and k is 4,
The list should be modified to 506010203040
6. Write a function detectAndRemoveLoop() that checks whether a given Linked List contains loop
and if loop is present then it returns true.
.
7. Given a Linked List of integers, write a function to modify the linked list such that all even
numbers appear before all the odd numbers in the modified linked list
Eg: Input: 17158121054176NULL
Output: 81210461715517NULL