Re: Banker's algorithm in c++
From: Michael Jørgensen (ingen_at_ukendt.dk)
Date: Mon, 15 Nov 2004 13:13:08 +0100
"c++" <firstname.lastname@example.org> wrote in message
> Michael Jørgensen wrote :
> > 2b) Have you checked that the value of 'lim' is correct everytime
> > through the loop? Print it to the screen, and you'll be able to
> > whether its value is what you expect.
> The biggest proble is that I don't konw how to tell to the user that if
> I have this vector:
> 10 | 2 | 1 | 11 | 3
> The PC should allocate the units requested by the process to the
> process nunber 3 (so the 4th reading from left)
> The second choice is the second biggest so is the nunber 0 (the firsth)
> and so on..
> but if we had a value -1 the process associated with it shold be NOT
I understand what you're trying to do, but I'm sure that the variable 'lim'
in your program is incorrect.
I've tried your program and the values of 'lim' do not look correct. For the
example with the five values given above, the value of lim becomes (at the
end of each iteration of the 'i' loop):
Are you sure this is correct? I expect you wanted the sequence to be 11, 10,
3, 2, 1. So you should try to figure out, why the program gets the wrong
value of the variable 'lim'.
Here is something more to think about: How is the variable 'MAX[i]' related
to the variable 'lim'? Should they always be the same?