Question: Write a program that creates a linked list of integers, and a function that deletes every node with a negative value in that list. Requirements:

Write a program that creates a linked list of integers, and a function that deletes every node with a negative value in that list.

Requirements:

1. Implement a deleteNegatives function: Node *deleteNegatives(Node *head); // example declaration This function should delete every negative node in the linked list and return a pointer to the new head of the list. Examples: * If the list is -3 -> 9 -> 2 -> -4 -> NULL , calling deleteNegatives(head) should change the list to be 9 -> 2 -> NULL and return a pointer to the new head. * If the list is 7 -> 6 -> 5 -> NULL , calling deleteNegatives(head) should leave the list the same and return a pointer to the old head.

2. Write a main function that creates a linked list of integers, then calls the function defined in part (1) to delete all the negative values. Call it on multiple lists to show that it works in all cases, and print out the results.

3. Test your function to make sure that it works in every case, no matter how many nodes or negative values are in the linked list

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!