Let \(LIST \) be a datatype for an implementation of linked list defined as…

GATE · 2025 · CS · Set 1 · Computer Science & IT

Let LISTLIST be a datatype for an implementation of linked list defined as follows:

typedef struct list {int data;struct list *next;} LIST;\begin{array}{l} \text{typedef struct list \{} \\ \quad \text{int data;} \\ \quad \text{struct list *next;} \\ \text{\} LIST;} \end{array}

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)

int find (int query, LIST *list) {while (list != NULL) {if (list->data == query) return 1;list = list->next;}return 0;}int main () {... ... ...ptr1 = L1; ptr2 = L2;while (ptr1->next != NULL) {query = ptr1->next->data;if (find (query, L2))ptr1->next = ptr1->next->next;else ptr1 = ptr1->next;}... ... ...return 0;}\begin{array}{l} \text{int find (int query, LIST *list) \{} \\ \quad \text{while (list != NULL) \{} \\ \quad\quad \text{if (list->data == query) return 1;} \\ \quad\quad \text{list = list->next;} \\ \quad \text{\}} \\ \quad \text{return 0;} \\ \text{\}} \\[10pt] \text{int main () \{} \\ \quad \text{... ... ...} \\ \quad \text{ptr1 = L1; ptr2 = L2;} \\ \quad \text{while (ptr1->next != NULL) \{} \\ \quad\quad \text{query = ptr1->next->data;} \\ \quad\quad \text{if (find (query, L2))} \\ \quad\quad\quad \text{ptr1->next = ptr1->next->next;} \\ \quad\quad \text{else ptr1 = ptr1->next;} \\ \quad \text{\}} \\ \quad \text{... ... ...} \\ \quad \text{return 0;} \\ \text{\}} \end{array}

Attempted by 192 students.

Sign up free to check your answer

Sign up free

Explore the full course: Gate Guidance By Sanchit Sir

Loading lesson…