Re: Banker's algorithm in c++

From: Michael Jørgensen (
Date: 11/15/04

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

"c++" <> 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?


Relevant Pages

  • Re: Exercise from Kernagan and Richie
    ... keeps the main loop control together as a unit in the for statement ... hands by avoiding a language feature that does exactly what's needed? ... challenge to test understanding. ... i = lim - 2; ...
  • Re: critique my program!
    ... One person already recommended against the definition for ZER, ... The difference is that LIM, presumably an abbreviation for limit, can be seen as a parameter. ... void printar; ... There are many ways to write a loop for a fixed number of iterations, as you do with the while loop. ...
  • TclX loop slow in the default case
    ... I wanted to see how much faster the Tclx loop command was compared to ... proc loop_default {lim} { ... proc loop_explicit { ...
  • Re: efficiency problem
    ... Miroslaw Osys wrote: ... As long as length is not changing outside the loop, ... declarations for i and lim that might speed up things a bit more. ...