The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
0 votes

Consider the function f defined below.

    struct item {
        int data;
        struct item * next;
int f(struct item *p) {
    return ((p == NULL) || (p->next == NULL)|| 
        ((p->data <= p ->next -> data) &&

For a given linked list p, the function  f returns 1 if and only if

  1. the list is empty or has exactly one element

  2. the elements in the list are sorted in non-decreasing order of data value

  3. the elements in the list are sorted in non-increasing order of data value

  4. not all elements in the list have the same data value


I m not getting it ,there is no return 1 statment so how thiz will right ?

asked in DS by Active (2.5k points) | 63 views

1 Answer

0 votes

Option B)  return ((p == NULL) || (p->next == NULL)|| ((p->data <= p ->next -> data) && f(p->next))). Look at the return condition carefully. F will return true only if the value of all successive nodes are greater than the previous node. If there are no nodes or if there is only one node even then this function will return true. Hence the OR conditions (p == NULL) || (p->next == NULL).

answered by Loyal (4.6k points)
cn u draw diagram by taking simple example


Related questions

0 votes
0 answers
asked ago in Programming by hem chandra joshi Loyal (3.4k points) | 20 views
0 votes
1 answer
+1 vote
1 answer
asked in CO & Architecture by Rajesh R Active (1.3k points) | 44 views

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

28,834 questions
36,688 answers
34,641 users