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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started