What is the functionality of the following piece of code? Select the most…

PYQ AMCAT 2023

What is the functionality of the following piece of code? Select the most appropriate.

public void function(int data)

{

int flag = 0;

if( head != null)

{

Node temp = head.getNext();

while((temp != head) && (!(temp.getItem() == data)))

{

temp = temp.getNext();

flag = 1;

break;

}

}

if(flag)

System.out.println("success");

else

System.out.println("fail");

}

  1. A.

    Print success if a particular element is not found

  2. B.

    Print fail if a particular element is not found

  3. C.

    Print success if a particular element is equal to 1

  4. D.

    Print fail if the list is empty

Attempted by 102 students.

Sign up free to check your answer

Sign up free

Explore the full course: Cdac C Cat Complete Preparation

Loading lesson…