GATE CS 2025 (Forenoon) — Question 62

Data StructuresLinked Lists & Binary TreesNAT2 marksHard

Let LIST be a datatype for an implementation of linked list defined as follows:
c
1typedef struct list {
2    int data;
3    struct list *next;
4} LIST;
5
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)
Question image
c
1int find (int query, LIST *list) {
2    while (list != NULL) {
3        if(list -> data == query) return 1;
4        list = list -> next;
5    }
6    return 0;
7}
8int main( ) {
9    ... ... ...
10    ptr1=L1; ptr2=L2;
11    while (ptr1 -> next != NULL) {
12        query = ptr1 -> next -> data;
13        if (find (query, L2))
14            ptr1 -> next = ptr1 -> next -> next;
15        else ptr1 = ptr1 -> next;
16    }
17    ... ... ...
18    return 0;
19}
20
Practise the full 2025-FN paper
Challenge a friend: WhatsApp Telegram
Recommended book · affiliate linkIntroduction to Algorithms (CLRS)The standard reference behind most GATE algorithm questions.
Practise more on Linked Lists & Binary TreesTimed, in the real exam interface · free to start

A GATE question every morning

One real past-paper question every morning for your branch, answer hidden until you tap. Free on Telegram.

Join
Stuck? Ask in the student group