ExamVeda
Login
Home
71
The following C function takes a single-linked list of integers as a parameter and rearranges the elements of the list. The function is called with the list containing the integers 1, 2, 3, 4, 5, 6, 7 in the given order. What will be the contents of the list after the function completes execution?
struct node 
{
    int value;
    struct node *next;
};
void rearrange(struct node *list)
{
    struct node *p, * q;
    int temp;
    if ((!list) || !list->next) 
      return;
    p = list;
    q = list->next;
    while(q) 
    {
         temp = p->value;
         p->value = q->value;
         q->value = temp;
         p = q->next;
         q = p?p->next:0;
    }
}
Discuss
Answer & Solution
Answer: Option B
No explanation is given for this question. Let's Discuss on Board
72
Consider the following definition in c programming language.
struct node
{
    int data;
    struct node * next;
}
typedef struct node NODE;
NODE *ptr;

Which of the following c code is used to create new node?
Discuss
Answer & Solution
Answer: Option A
No explanation is given for this question. Let's Discuss on Board
73
What does the following function do?
public Object some_func()throws emptyStackException
{
	if(isEmpty())
		throw new emptyStackException("underflow");
	return first.getEle();
}
Discuss
Answer & Solution
Answer: Option C
No explanation is given for this question. Let's Discuss on Board
74
What is the output of the following program?
public class Stack
{
	protected static final int CAPACITY = 100;
	protected int size,top = -1;
	protected Object stk[];
 
	public Stack()
	{
		stk = new Object[CAPACITY];
	}
 
	public void push(Object item)
	{
		if(size_of_stack==size)
		{
			System.out.println("Stack overflow");
				return;
		}
		else
		{
			top++;
			stk[top]=item;
		}
	}
	public Object pop()
	{
		if(top<0)
		{
			return -999;
		}
		else
		{
			Object ele=stk[top];
			top--;
			size_of_stack--;
			return ele;
		}
	}
}
 
public class StackDemo
{
	public static void main(String args[])
	{
		Stack myStack = new Stack();
		myStack.push(10);
		Object element1 = myStack.pop();
		Object element2 = myStack.pop();
		System.out.println(element2);
	}
}
Discuss
Answer & Solution
Answer: Option D
No explanation is given for this question. Let's Discuss on Board
75
The postfix form of the expression (A+ B)*(C*D- E)*F / G is?
Discuss
Answer & Solution
Answer: Option C
No explanation is given for this question. Let's Discuss on Board
76
What is the functionality of the following piece of code?
public int function()
{
	Node temp = tail.getPrev();
	tail.setPrev(temp.getPrev());
	temp.getPrev().setNext(tail);
	size--;
	return temp.getItem();
}
Discuss
Answer & Solution
Answer: Option D
No explanation is given for this question. Let's Discuss on Board
77
How do you insert a node at the beginning of the list?
Discuss
Answer & Solution
Answer: Option A
No explanation is given for this question. Let's Discuss on Board
78
What is the time complexity to count the number of elements in the linked list?
Discuss
Answer & Solution
Answer: Option B
No explanation is given for this question. Let's Discuss on Board
79
Given below is the Node class to perform basic list operations and a Stack class with a no arg constructor.
Select from the options the appropriate pop() operation that can be included in the Stack class. Also 'first' is the top-of-the-stack.
class Node
{
	protected Node next;
	protected Object ele;
	Node()
	{
		this(null,null);
	}
	Node(Object e,Node n)
	{
		ele=e;
		next=n;
	}
	public void setNext(Node n)
	{
		next=n;
	}
	public void setEle(Object e)
	{
		ele=e;
	}
	public Node getNext()
	{
		return next;
	}
	public Object getEle()
	{
		return ele;
	}
}
 
class Stack
{
	Node first;
	int size=0;
	Stack()
	{
		first=null;
	}
}
Discuss
Answer & Solution
Answer: Option A
No explanation is given for this question. Let's Discuss on Board
80
Process of removing an element from stack is called . . . . . . . .
Discuss
Answer & Solution
Answer: Option D
No explanation is given for this question. Let's Discuss on Board