Re: Converting recursive algorithm to an iterative version
On 12/7/2011 6:48 PM, Ania wrote:
Here is my problem:
I implemented recurive algorithm in c++ for a problem given below:
I have a list of items (only positive integers are allowed) and fixed
number of bins of identical capacity. I need to pack items (if
possible) so that elements in each bin sum up to given capacity.
I try to convert my recursive algorithm to an one. However, my
implementation with explicit stack doesn't work as I expected.
What does that mean? What did you expect? What does it do? Do you
think we should be guessing or dusting off our crystal ball?
> I can't
pinpoint the place where I have made a mistake.
Have you tried using a "debugger" and step through your code? Do you
have a test case? Do you know what values of your objects need to be on
every step of your algorithm? If you do, just fire off that debugger
(whichever you got, all pretty much work when you know what you're
doing) and execute your test program step by step, and verify that the
values of the objects as they need to be. If they aren't make changes
to the code.
If you don't have a test case, get yourself one. If you don't know what
values of your objects should be at every point in your program... did
you actually write your program yourself? If you did, you should. Do
you know how to use a debugger? If you don't, it looks like it's time
to learn.
Bite the bullet and fix your own program. Otherwise, find a different
field to develop your skills.
V
--
I do not respond to top-posted replies, please don't ask