Consider the following function to traverse a linked list.
// C++ version of traverse function
void traverse(Node *head) {
while (head != NULL) {
printf("%d ", head->data);
head = head->next;
}
}
void traverse(struct Node *head)
{
while (head->next != NULL)
{
printf("%d ", head->data);
head = head->next;
}
}
// Java version of traverse function
void traverse(Node head) {
while (head != null) {
System.out.print(head.data + " ");
head = head.next;
}
}
# Python 3 version of traverse function
def traverse(head):
while head is not None:
print(head.data, end=' ')
head = head.next
// JavaScript version of traverse function
function traverse(head) {
while (head !== null) {
console.log(head.data + ' ');
head = head.next;
}
}
Which of the following is FALSE about above function?
The function may crash when the linked list is empty
The function doesn't print the last node when the linked list is not empty
The function is implemented incorrectly because it changes head
None of the above
This question is part of this quiz :
Top MCQs on Linked List Data Structure with Answers