Assignment 2
Assignment 2
DSA (CSE2131)
Single Linked List, Double Linked List
Execute and write the following programs for all possible test cases.
Q1. Merge two sorted linked lists and return it as a new sorted list.
Input: 1 -> 2 -> 4, 1 -> 3 -> 4
Q3. Given a linked list, remove the n-th node from the end of the list and return its head.
Input: 1 -> 2 -> 3 -> 4 -> 5, n = 2
Output: 1 -> 2 -> 3 -> 5
Q4. Write a program to reverse a singly linked list by changing link of node only.
Input: 1 -> 2 -> 3 -> 4 -> 5 -> NULL
Output: 5 -> 4 -> 3 -> 2 -> 1 -> NULL
Q5. Given a sorted doubly linked list, find pairs with a given sum.
Input: 1 <-> 2 <-> 4 <-> 5 <-> 6 <-> 8 <-> 9, sum = 7
Output: (1, 6), (2, 5)