Computer Sciences > GATE 2025 SET-1 > Linked Lists
Let LIST be a datatype for an implementation of 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 ______ (Answer in integer)

Correct : 5

The number of nodes remaining in L1 after execution is 5.
The code does one thing — it walks through L1 and deletes any node whose data value is also present in L2. The find() function performs a linear search through L2 for each node of L1.
The logic works like this: ptr1 always points to the node just before the one being checked. If ptr1->next->data is found in L2, the next node gets deleted by setting ptr1->next = ptr1->next->next, bypassing it entirely. If not found, ptr1 simply advances to the next node.
Note that ptr1 never moves when a deletion happens — this ensures consecutive matching nodes are all caught and removed without skipping any.
From the given lists, 4 out of 9 nodes in L1 have data values that also appear in L2. After those 4 deletions, 9 - 4 = 5 nodes remain in L1.

Similar Questions

Consider the following code snippet in C language that computes the number of nodes in a non-empty singly linked list pointed to by the pointer variable head.st...
#1525 MCQ
A palindrome is a word that reads the same forwards and backwards. In a game of words, a player has the following two plates painted with letters. From...
#1 MCQ
Which number does not belong in the series below? 2, 5, 10, 17, 26, 37, 50, 64
#4 MCQ

Related Topics

GATE CS 2025 GATE CS 2025 Set-1 Q62 Linked List Node Deletion L1 L2 Linked List C Linked List Program Remove Nodes Linked List find() Function Pointer Manipulation Data Structures GATE GATE CS 2025 Solved Singly Linked List Node Count After Deletion

Unique Visitor Count

Total Unique Visitors

Loading......