Re: Banker's algorithm in c++

From: Michael Jørgensen (ingen_at_ukendt.dk)
Date: 11/15/04


Date: Mon, 15 Nov 2004 13:13:08 +0100


"c++" <mirkospagnol@aliceposta.it> wrote in message
news:mn.7a857d4b8395d7b2.22414@aliceposta.it...
> 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
determine
> > whether its value is what you expect.

[snip]

> 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
> SECURE.

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):
11
10
2
1
1

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?

-Michael.