Question:medium

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
Show Solution

Correct Answer: 5

Solution and Explanation

The final content of L1 depends only on which of its values also appear in L2. Any value common to both lists does not remain in L1, while values unique to L1 stay unchanged.

Comparing the two lists:

  • Common values in both lists: 11, 9, 12, 15
  • Values appearing only in L1: 1, 7, 3, 5, 8

After excluding the common elements, L1 contains exactly five values.

Hence, the number of nodes left in L1 is \(\boxed{5}\).

Was this answer helpful?
0