Question:

Let LIST be a datatype for an implementation of a linked list defined as follows:
typedef struct list {
    int data;
    struct list next;
} LIST;
Suppose a program has created two linked lists, L1 and L2, whose contents are given in the figure below (code for creating L1 and L2 is not provided here). L1 contains 9 nodes, and L2 contains 7 nodes. Consider the following C program segment that modifies the list L1. The number of nodes that will be there in L1 after the execution of the code segment is:
\includegraphics[width=0.5\linewidth]{62.png}

Show Hint

When working with linked lists in C, carefully track how nodes are added or removed by considering conditions and traversals through the list.
Updated On: Jan 30, 2026
Hide Solution
collegedunia
Verified By Collegedunia

Correct Answer: 5

Solution and Explanation

The program iterates through the linked list L1 and checks for the presence of each element from L1 in L2 using the function `find()`. If an element from L1 is found in L2, the corresponding node in L1 is removed. The `find()` function returns `1` when a match is found, and `0` otherwise. In the given lists:
- L1: 1 → 7 → 12 → 3 → 9 → 5 → 11 → 15 → 8
- L2: 11 → 6 → 9 → 15 → 12 → 4
The values `11`, `9`, `12`, and `15` are found in L2, and their corresponding nodes are removed from L1.
After the removal process, the remaining nodes in L1 will be:
1 → 7 → 3 → 5 → 8
Thus, the number of nodes left in L1 is 5.
Was this answer helpful?
0
0