Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a list map function that takes 3 arguments: (1) a pointer to a source struct list, a pointer to a destination struct list,

Write a list map function that takes 3 arguments: (1) a pointer to a  5 test functions: 2 test functions that test the functionality of list map, and 3 test functions that test

Write a list map function that takes 3 arguments: (1) a pointer to a "source" struct list, a pointer to a "destination" struct list, and (2) a pointer to function that takes an int argument and returns an int. The list map function will loop through the nodes of the "source" list and at every node the provided function is called (using the function pointer) with one argument: the int value found inside the current struct node. The returned int from the function is then appended to the "destination" list. list map does not return anything. Question 2 [40 points] Write a list reduce function that takes 3 arguments: (1) a pointer to a struct list, (2) a pointer to function that takes two int arguments and returns an int, and (3) a "default" int value. If the list has zero nodes, list reduce returns the "default" int value. If the list has one node, list reduce will return the int value found within the single node in the list. Otherwise, list reduce should start by calling the provided function (using the function pointer) on the first two int values in the node chain and put the returned value in an "accumulator" int variable. After that, list reduce should loop through the node chain (starting from the 3rd node) and at every node the provided function is called with two arguments: the "accumulator" int variable, and the int value of the current struct node. The returned value from the function is then used to update the "accumulator". The function returns the "accumulator". Question 3 [25 points] The provided list.c file contains a number of test functions and a main() function that runs the test functions. Do not alter any of the existing tests. In this part, you will add 5 test functions: 2 test functions that test the functionality of list map, and 3 test functions that test the functionality of list reduce. Make sure to add these test functions to the array of tests in main() using appropriate test names. The test functions should return NULL if the test is successful or an appropriate error message otherwise (the return type is const char * to allow returning literal strings as shown in the provided test functions). Files to hand in All source files must be on git. The following files are to be packaged into a tarball a6.tar (located at the root of the repository; i.e., not in any subdirectories) and committed to git with the commit message "a6 hand-in": - Makefile (you may use the same Makefile that you handed-in for A5) list.c

Step by Step Solution

There are 3 Steps involved in it

Step: 1

include include Define a struct for a linked list node containing an integer value struct ListNode i... 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

C++ Primer Plus

Authors: Stephen Prata

6th Edition

978-0321776402, 0321776402

More Books

Students also viewed these Computer Network questions