Introduction To Data Structures - Study Mode
[#181] What is the output of following function for start pointing to first node of following linked list? 1->2->3->4->5->6
void fun(struct node* start)
{
if(start == NULL)
return
printf("%d ", start->data)
if(start->next != NULL )
fun(start->next->next)
printf("%d ", start->data)
}
Correct Answer
(D) 1 3 5 5 3 1
[#182] Making the push operation costly, select the code snippet which implements the pop operation.
Correct Answer
(B) public void pop()
{
if(q1.size()>0)
{
q1.poll()
}
else if(q2.size()>0)
{
q2.poll()
}
}
[#183] What does the following Java code do? public Object function()
{
if(isEmpty())
return -999
else
{
Object high
high = q[front]
return high
}
}
Correct Answer
(C) Return the front element
[#184] What is the functionality of the following piece of Java code? Assume: 'a' is a non empty array of integers, the Stack class creates an array of specified size and provides a top pointer indicating TOS(top of stack), push and pop have normal meaning. public void some_function(int[] a)
{
Stack S=new Stack(a.length)
int[] b=new int[a.length]
for(int i=0
i<a.length
i++)
{
S.push(a[i])
}
for(int i=0
i<a.length
i++)
{
b[i]=(int)(S.pop())
}
System.out.println("output :")
for(int i=0
i<b.length
i++)
{
System.out.println(b[i])
}
}
Correct Answer
(D) reverse the array
[#185] Select the code snippet which return true if the stack is empty, false otherwise.
Correct Answer
(B) public boolean empty()
{
return q1.isEmpty() || q2.isEmpty()
}