Data Structures | Linked List | Question 11
Consider the function f defined below.
item * next;
(p == NULL) ||
(p->next == NULL) ||
(( p->data <= p->next->data) && f(p->next))
For a given linked list p, the function f returns 1 if and only if (GATE CS 2003)
not all elements in the list have the same data value.
the elements in the list are sorted in non-decreasing order of data value
the elements in the list are sorted in non-increasing order of data value
None of them
The function checks if the current element is less than or equal to the next element, and recursively applies the same check to the next element. If the end of the list is reached (i.e., p->next is NULL), or the next element is less than the current element, the function returns 1. Otherwise, it returns 0. Therefore, the function returns 1 only if the linked list is sorted in non-decreasing order.
Quiz of this Question
Please comment below if you find anything wrong in the above post