Introduction To Data Structures - Study Mode
[#171] What is the functionality of the following piece of code? public void function(Object item)
{
Node temp=new Node(item,trail)
if(isEmpty())
{
head.setNext(temp)
temp.setNext(trail)
}
else
{
Node cur=head.getNext()
while(cur.getNext()!=trail)
{
cur=cur.getNext()
}
cur.setNext(temp)
}
size++
}
Correct Answer
(B) Insert at the rear end of the dequeue
[#172] Consider the following doubly linked list: head-1-2-3-4-5-tail. What will be the list after performing the given sequence of operations? Node temp = new Node(6,head,head.getNext())
Node temp1 = new Node(0,tail.getPrev(),tail)
head.setNext(temp)
temp.getNext().setPrev(temp)
tail.setPrev(temp1)
temp1.getPrev().setNext(temp1)
Correct Answer
(C) head-6-1-2-3-4-5-0-tail
[#173] Consider the following operation performed on a stack of size 5. Push(1)
Pop()
Push(2)
Push(3)
Pop()
Push(4)
Pop()
Pop()
Push(5)
After the completion of all operation, the number of elements present in stack is?
Correct Answer
(A) 1
[#174] What is the functionality of the following code? public void function(Node node)
{
if(size == 0)
head = node
else
{
Node temp,cur
for(cur = head
(temp = cur.getNext())!=null
cur = temp)
cur.setNext(node)
}
size++
}
Correct Answer
(C) Inserting a node at the end of the list
[#175] The following function reverse() is supposed to reverse a singly linked list. There is one line missing at the end of the function. /* Link list node */
struct node
{
int data
struct node* next
}
/* head_ref is a double pointer which points to head (or start) pointer
of linked list */
static void reverse(struct node** head_ref)
{
struct node* prev = NULL
struct node* current = *head_ref
struct node* next
while (current != NULL)
{
next = current->next
current->next = prev
prev = current
current = next
}
/*ADD A STATEMENT HERE*/
} What should be added in place of "/*ADD A STATEMENT HERE*/", so that the function correctly reverses a linked list.
Correct Answer
(A) *head_ref = prev