Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Web Database Development Step By Step

Authors: Jim Buyens

1st Edition

0735609667, 978-0735609662

More Books

Students also viewed these Databases questions