Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Knapsack Problem. - Your implementation must rely on a dynamic allocation of memory to store the items in the knapsack. HEADERFILE PROVIDED BELOW Our knapsack

Knapsack Problem. - Your implementation must rely on a dynamic allocation of memory to store the items in the knapsack. image text in transcribedimage text in transcribedHEADERFILE PROVIDED BELOW

image text in transcribedimage text in transcribed

Our knapsack data structure simply stores a set of items (integer values) and their counts. The header file task2/knapsack.h provides the definitions and the prototypes of the functions for our knapsack. Your task is to implement the functions specified in the header file in a new source file called knapsack.c. I have provided detailed comments about the job of each function, its parameters, and its expected output. You are free to implement more helper functions in your source if needed. But any program should be able to use your knapsack functions by just including the existing header file and accessing the compiled version of your knapsack code. Note that your knapsack.c should not contain a main() function. In order to test your knapsack code, you should create a main() function in a separate file (say test_knapsack.c) which tests the functionality of your knapsack code by calling its functions. As discussed above, test_knapsack.c can only include knapsack.h (not knapsack.c ) You can then use gcc to compile and link your source codes to create an executable. Our knapsack data structure simply stores a set of items (integer values) and their counts. The header file task2/knapsack.h provides the definitions and the prototypes of the functions for our knapsack. Your task is to implement the functions specified in the header file in a new source file called knapsack.c. I have provided detailed comments about the job of each function, its parameters, and its expected output. You are free to implement more helper functions in your source if needed. But any program should be able to use your knapsack functions by just including the existing header file and accessing the compiled version of your knapsack code. Note that your knapsack.c should not contain a main() function. In order to test your knapsack code, you should create a main() function in a separate file (say test_knapsack.c) which tests the functionality of your knapsack code by calling its functions. As discussed above, test_knapsack.c can only include knapsack.h (not knapsack.c ) You can then use gcc to compile and link your source codes to create an executable

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

Students also viewed these Databases questions