Practice Top 30 C++ Programming Questions on Linked List, TechnoVlogs

Practice Top 30 C++ Programming Questions on Linked List


Q1. Write a program to create a singly linked list with three nodes and display their data.

Input:  
Enter values for 3 nodes: 10, 20, 30

Expected Output:  
Linked List: 10 -> 20 -> 30

Q2. Insert a node at the beginning of a singly linked list.

Input:  
Original List: 10 -> 20 -> 30  
Insert: 5

Expected Output:  
Updated List: 5 -> 10 -> 20 -> 30

Q3. Insert a node at the end of a singly linked list.

Input:  
Original List: 10 -> 20 -> 30  
Insert: 40

Expected Output:  
Updated List: 10 -> 20 -> 30 -> 40

Q4. Insert a node after a given node in a singly linked list.

Input:  
Original List: 10 -> 20 -> 30  
Insert: 25 after 20

Expected Output:  
Updated List: 10 -> 20 -> 25 -> 30

Q5. Delete the first occurrence of a given value from a linked list.

Input:  
Original List: 10 -> 20 -> 30  
Delete: 20

Expected Output:  
Updated List: 10 -> 30

Q6. Count the number of nodes in the linked list.

Input:  
Linked List: 10 -> 20 -> 30

Expected Output:  
Length: 3

Q7. Search for a value in the linked list and return its position.

Input:  
Linked List: 10 -> 20 -> 30  
Search: 20

Expected Output:  
Value 20 found at position 2.

Q8. Reverse the elements of a singly linked list.

Input:  
Original List: 10 -> 20 -> 30

Expected Output:  
Reversed List: 30 -> 20 -> 10

Q9. Find the middle node of a linked list.

Input:  
Linked List: 10 -> 20 -> 30 -> 40 -> 50

Expected Output:  
Middle Node: 30

Q10. Remove duplicate values from a sorted linked list.

Input:  
Linked List: 10 -> 10 -> 20 -> 30 -> 30

Expected Output:  
Updated List: 10 -> 20 -> 30

Q11. Detect if a loop exists in the linked list.

Input:  
Linked List: 10 -> 20 -> 30 -> (points back to 20)

Expected Output:  
Loop Detected

Q12. Merge two sorted linked lists into one.

Input:  
List1: 10 -> 20 -> 30  
List2: 15 -> 25

Expected Output:  
Merged List: 10 -> 15 -> 20 -> 25 -> 30

Q13. Find the nth node from the end of the linked list.

Input:  
Linked List: 10 -> 20 -> 30 -> 40  
N: 2

Expected Output:  
Nth Node from End: 30

Q14. Delete the entire linked list.

Input:  
Linked List: 10 -> 20 -> 30

Expected Output:  
Linked List Deleted

Q15. Split a linked list into two equal halves.

Input:  
Linked List: 10 -> 20 -> 30 -> 40

Expected Output:  
First Half: 10 -> 20  
Second Half: 30 -> 40

Q16. Check if the linked list is a palindrome.

Input:  
Linked List: 10 -> 20 -> 20 -> 10

Expected Output:  
Palindrome

Q17. Find the intersection point of two linked lists.

Input:  
List1: 10 -> 20 -> 30  
List2: 15 -> (points to 20 in List1)

Expected Output:  
Intersection Point: 20

Q18. Sort a linked list in ascending order.

Input:  
Linked List: 30 -> 10 -> 20

Expected Output: 
Sorted List: 10 -> 20 -> 30

Q19. Rotate a linked list by k positions to the right.

Input:  
Linked List: 10 -> 20 -> 30 -> 40  
Rotate: 2

Expected Output:  
Rotated List: 30 -> 40 -> 10 -> 20

Q20. Find the maximum value node in a linked list.

Input:  
Linked List: 10 -> 50 -> 20

Expected Output:  
Maximum Node: 50

Q21. Flatten a multilevel linked list where each node may have a child linked list.

Input:  
Multilevel List: 
1 -> 2 -> 3  
    |  
    4 -> 5

Expected Output:  
Flattened List: 1 -> 2 -> 4 -> 5 -> 3

Q22. Convert a linked list to an array.

Input:  
Linked List: 10 -> 20 -> 30

Expected Output:  
Array: [10, 20, 30]

Q23. Convert an array to a linked list.

Input:  
Array: [10, 20, 30]

Expected Output:  
Linked List: 10 -> 20 -> 30

Q24. Swap two nodes in a linked list without swapping data.

Input:  
Linked List: 10 -> 20 -> 30 -> 40  
Swap: 20 and 30

Expected Output:  
Updated List: 10 -> 30 -> 20 -> 40

Q25. Check whether the linked list is circular or not.

Input:  
Linked List: 10 -> 20 -> 30 -> (points back to 10)

Expected Output:  
Circular Linked List: Yes

Q26. Add two numbers represented by linked lists.

Input:  
List1: 2 -> 4 -> 3 (represents 342)  
List2: 5 -> 6 -> 4 (represents 465)

Expected Output:  
Sum: 7 -> 0 -> 8 (represents 807)

Q27. Remove the kth node from the linked list.

Input:  
Linked List: 10 -> 20 -> 30 -> 40  
Remove: 3rd Node

Expected Output:  
Updated List: 10 -> 20 -> 40

Q28. If a loop exists, find the length of the loop.

Input:  
Linked List: 10 -> 20 -> 30 -> (points back to 20)

Expected Output:  
Loop Detected: Yes  
Loop Length: 2

Q29. Swap nodes in pairs in a linked list.

Input:  
Linked List: 10 -> 20 -> 30 -> 40

Expected Output:  
Updated List: 20 -> 10 -> 40 -> 30

Q30. Split a circular linked list into two halves.

Input:  
Circular Linked List: 10 -> 20 -> 30 -> 40 -> (points back to 10)

Expected Output:  
First Half: 10 -> 20 -> (points back to 10)  
Second Half: 30 -> 40 -> (points back to 30)

Social Share

Bikki Singh Instructor TechnoVlogs

Bikki Singh

Hi, I am the instructor of TechnoVlogs. I have a strong love for programming and enjoy teaching through practical examples. I made this site to help people improve their coding skills by solving real-world problems. With years of experience, my goal is to make learning programming easy and fun for everyone. Let's learn and grow together!