0% found this document useful (0 votes)
5 views1 page

Assignment 2

Uploaded by

Manasveer Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

Assignment 2

Uploaded by

Manasveer Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Assignment 2

DSA (CSE2131)
Single Linked List, Double Linked List

Instruction: All the programs must be implemented and handwritten in C language.

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

Output: 1 -> 1 -> 2 -> 3 -> 4 -> 4

Q2. Sort the double linked list in ascending order.

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)

You might also like