Introduction To Data Structures - Study Mode
[#201] What is the functionality of the following code? Choose the most appropriate answer. public int function()
{
if(head == null)
return Integer.MIN_VALUE
int var
Node temp = head
while(temp.getNext() != head)
temp = temp.getNext()
if(temp == head)
{
var = head.getItem()
head = null
return var
}
temp.setNext(head.getNext())
var = head.getItem()
head = head.getNext()
return var
}
Correct Answer
(D) Returns the data and deletes the node from the beginning of the list
[#202] What is the functionality of the following piece of code? public void fun(int x)
{
q1.offer(x)
}
Correct Answer
(B) Perform push() with pop as the costlier operation
[#203] What does the following function check for? (all necessary headers to be included and function is called from main) #define MAX 10
typedef struct stack
{
int top
int item[MAX]
}stack
int function(stack *s)
{
if(s->top == -1)
return 1
else return 0
}
Correct Answer
(C) empty stack
[#204] 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")
}
Correct Answer
(B) Print fail if a particular element is not found
[#205] How do you instantiate an array in Java?
Correct Answer
(C) int arr[] = new int[3]