gs gs122 Recursion - Length of a Linked List using Recursion - Quiz No.1
gs gs122 Data Communication and Computer Network Quiz
This quiz belongs to book/course code gs gs122 Data Communication and Computer Network of gs organization. We have 268 quizzes available related to the book/course Data Communication and Computer Network. This quiz has a total of 10 multiple choice questions (MCQs) to prepare and belongs to topic Recursion. NVAEducation wants its users to help them learn in an easy way. For that purpose, you are free to prepare online MCQs and quizzes.
NVAEducation also facilitates users to contribute in online competitions with other students to make a challenging situation to learn in a creative way. You can create one to one, and group competition on an topic of a book/course code. Also on NVAEducation you can get certifications by passing the online quiz test.
struct Node { int val; struct Node *next; }*head; int get_len() { struct Node *temp = head->next; int len = 0; while(_____) { len++; temp = temp->next; } return len; }
Which of the following conditions should be checked to complete the above code?
#include<stdio.h> #include<stdlib.h> struct Node { int val; struct Node *next; }*head; int get_len() { struct Node *temp = head->next; int len = 0; while(temp != 0) { len++; temp = temp->next; } return len; } int main() { int arr[10] = {1,2,3,4,5}, n = 5, i; struct Node *temp, *newNode; head = (struct Node*)malloc(sizeof(struct Node)); head->next = 0; int len = get_len(); printf("%d",len); return 0; }
#include<stdio.h> #include<stdlib.h> struct Node { int val; struct Node *next; }*head; int recursive_get_len(struct Node *current_node) { if(current_node == 0) return 0; return _____; } int main() { int arr[10] = {1,2,3,4,5}, n = 5, i; struct Node *temp, *newNode; head = (struct Node*)malloc(sizeof(struct Node)); head->next = 0; temp = head; for(i=0; i<n; i++) { newNode = (struct Node*)malloc(sizeof(struct Node)); newNode->val = arr[i]; newNode->next = 0; temp->next = newNode; temp = temp->next; } int len = recursive_get_len(head->next); printf("%d",len); return 0; }