Question: Suppose we have a singly linked list implemented with the structure below. Write a recursive function that takes in the list and returns 1 if

Suppose we have a singly linked list implemented with the structure below. Write a recursive function that takes in the list and returns 1 if the list is non-empty AND all of the numbers in the list are even, and returns 0 if the list is empty OR contains at least one odd integer. (For example, the function should return 0 for an empty list, 1 for a list that contains 2 only, and 0 for a list that contains 3 only.) struct node { int data; struct node* next; }; int check_all_even (struct node *head) { // Grading: 2 pts if (head == NULL) return 0; // Grading: 4 pts, we have to have this here to // differentiate between an empty and non-empty list. // 2 pts for checking next is NULL, 1 pt for each return. if (head->next == NULL) { if (head->data % 2 == 0) return 1; } else return 0; // Grading: 1 pt if, 1 pt return if (head->data % 2 != 0) return 0; // Grading: 2 pts return check all even (head->next)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!