MCQ IN COMPUTER SCIENCE & ENGINEERING

COMPUTER SCIENCE AND ENGINEERING

DATA STRUCTURES

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
Consider a list with head node as L, if one wants to search an element and find its position too, what code he has follow? Assume P is of the type of struct which defines the list.
A
for(P=L;P!=NULL;P=P
B
for(P=L;P!=NULL;P=P
C
for(P=L;P!=NULL;P=P
D
for(P=L;P!=data;P=P
Explanation: 

Detailed explanation-1: -What does the following function do for a given Linked List with first node as head? Explanation: fun1() prints the given Linked List in reverse manner.

Detailed explanation-2: -The entry point into a linked list is called the head of the list. It should be noted that head is not a separate node, but the reference to the first node. If the list is empty then the head is a null reference. A linked list is a dynamic data structure.

Detailed explanation-3: -What should be added in place of “/*ADD A STATEMENT HERE*/”, so that the function correctly reverses a linked list. Explanation: *head ref = prev; At the end of while loop, the prev pointer points to the last node of original linked list.

Detailed explanation-4: -Time Complexity: O(n), as list traversal is needed.

There is 1 question to complete.