-
knapsack problem
i have algorithm for the knap sack i want to convert it to c++ langugh
can you advice me ?
can i use a file to put the data ?
for example i have knap sack for year 2000, year 2001 and year2002
and each of them have a size and value
thue i have to create a 3 files
but how can i delete the data from the files`for the next user
or do you have another solution or better than the file???
thank you
-
You can delete a file with with the ANSI C (and thus C++) standard function remove() in <cstdio>. (Make sure that you don't have any open streams referring to the file first.)
But it's probably a bad design to write the data into a file (or three). Why not just create three separate variables? Or better yet, one function which handles any knapsack, which you then call three times?
Also, if you want to learn more about the knapsack problem itself, try this Wikipedia entry. http://en.wikipedia.org/wiki/Knapsack_problem