Which of the following options is the correct code for traversing a link list staring at pointer P, upto element X ?
Show answerHide answer
Correct answer: (D) While (P ! = NULL && P → Element ! = X) P = P → Next ;
Explanation
The loop must stop at the end of the list or when X is found, so it continues only while P != NULL && P→Element != X. Checking for NULL first also avoids dereferencing a null pointer.