Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I dont understand why you have to check if sum == -1. Can someone please explain. 3) (10pts) DSN (Linked Lists) Write a recursive function

image text in transcribedI dont understand why you have to check if sum == -1. Can someone please explain.

3) (10pts) DSN (Linked Lists) Write a recursive function that takes the head of a linked list (possibly NULL) that contains positive integers only. The function must return-1 if the list contains any integer that is equal to the sum of all integers that come after it in the list. If not, the function can return whatever value you feel is appropriate other than -1. (Figuring out what to return is part of the fun for this problem.) For example, the function should return-1 for the following linked list because 4 is the sum of all the nodes that follow it (1, 2, and 1): 20-3 -1->4-1-> 2->1-NULL head The function signature and node struct are: typedef struct node ( int data; struct node *next; node int listylist (node *head) int sum if (head= NULL) return 0 sumlistylist(head->next); if (sum head->datasum) return -1; return head->data sum

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

Step: 3

blur-text-image

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

Database Concepts International Edition

Authors: David M. Kroenke

6th Edition International Edition

0133098222, 978-0133098228

More Books

Students also viewed these Databases questions

Question

=+2 Why did OBI create Centers of Excellence?

Answered: 1 week ago