Question 66Asked in BEL PE Computer Science, 20 Dec 2025 (5:00 PM)

A developer implements the following code to sort a singly linked list using bubble sort by swapping data instead of links:

A developer implements the following code to sort a singly linked list using bubble sort by swapping data instead of links: void sort(struct Node *head) { struct Node *i, *j; int temp; for (i = head; i != NULL; i = i->next) { for (j = i->next; j != NULL; j = j->next) { if (i->data > j->data) { temp = i->data; i->data = j->data; j->data = temp; } } } } After sorting, the program prints the list, but the last element sometimes remains unsorted when the list contains duplicate values. What is the most likely conceptual issue?
  1. AThe inner loop should compare j->next instead of j to avoid null dereferencing.
  2. BSwapping node data breaks pointer consistency in linked lists with duplicate values.
  3. CThe outer loop must run until no swaps occur, not just until i == NULL.
  4. DThe issue arises because swapping data does not rearrange links, so duplicates are skipped.
Show answerHide answer

Correct answer: (C) The outer loop must run until no swaps occur, not just until i == NULL.

From BEL PE Computer Science PYQ, 20 Dec 2025 (5:00 PM)

This is question 66 of BEL PE Computer Science PYQ, 20 Dec 2025 (5:00 PM). See all questions of this paper with answers, or attempt the paper as a timed online test to get your score and all-India rank.