MCQ IN COMPUTER SCIENCE & ENGINEERING

COMPUTER SCIENCE AND ENGINEERING

DATA STRUCTURES

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
Which is the correct code to acess the second node in a linked list?
A
head.getData()
B
head.getNext().getData()
C
head.getNext().getNext().getData()
D
none of the above
Explanation: 

Detailed explanation-1: -As in singly linked list, each node in circular linked list consists of two parts. The first part can be said as information or data part and the second part is called link field which contains address of next node in the list or is null.

Detailed explanation-2: -The idea is to traverse the linked list following the below approach: If the list is empty or contains less than 2 elements, return false. Otherwise, check if the current node is the second last node of the linked list or not. That is, if (current node->next-next == NULL ) then the current node is the second last node.

Detailed explanation-3: -getNext(); sets the value of second element of the LinkedList link into edgeLine, and then you loop and do the same, and then the same over and over and over again.

Detailed explanation-4: -node* next; means: next is a pointer to a node structure, and indicates the next item in the list.

There is 1 question to complete.