Consider the function f defined below.
#include <iostream>
struct item {
int data;
struct item *next;
};
int f(struct item *p) {
return (
(p == NULL) ||
(p->next == NULL) ||
((p->data <= p->next->data) && f(p->next))
);
}
struct item
{
int data;
struct item * next;
};
int f(struct item *p)
{
return (
(p == NULL) ||
(p->next == NULL) ||
(( p->data <= p->next->data) && f(p->next))
);
}
class Item {
int data;
Item next;
Item(int data) {
this.data = data;
this.next = null;
}
}
public class Main {
public static boolean f(Item p) {
return (
(p == null) ||
(p.next == null) ||
((p.data <= p.next.data) && f(p.next))
);
}
}
class Item:
def __init__(self, data):
self.data = data
self.next = None
def f(p):
return (
p is None or
p.next is None or
(p.data <= p.next.data and f(p.next))
)
class Item {
constructor(data) {
this.data = data;
this.next = null;
}
}
function f(p) {
return (
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
This question is part of this quiz :
Top MCQs on Linked List Data Structure with Answers