What is the functionality of the following piece of code? Select the most appropriate. [code] public void function(int data) { int flag

What is the functionality of the following piece of code? Select the most appropriate.
Code:
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");
}
A. Print success if a particular element is not found
B. Print fail if a particular element is not found
C. Print success if a particular element is equal to 1
D. Print fail if the list is empty
 
Answer: B
Explanation: The function prints fail if the given element is not found. Note that this option is inclusive of option “Print fail if the list is empty”, the list being empty is one of the cases covered.
 

Tìm kiếm

Back
Top