Banker's algorithm: Difference between revisions
Content added Content deleted
(Banker's algorithm en FreeBASIC) |
(Banker's algorithm en Yabasic) |
||
Line 1,985: | Line 1,985: | ||
Available Vector: 8 5 9 7 |
Available Vector: 8 5 9 7 |
||
</pre> |
</pre> |
||
=={{header|Yabasic}}== |
|||
{{trans|FreeBASIC}} |
|||
<lang yabasic> |
|||
clear screen |
|||
input "Ingrese la cantidad de recursos: " r |
|||
input "Ingrese la cantidad de procesos: " p |
|||
print "\nIngrese los recursos m ximos: " |
|||
dim maxRes(r) |
|||
for i = 1 to r |
|||
input " " maxRes(i) |
|||
next i |
|||
print "\n-- recursos asignados para cada proceso --" |
|||
dim curr(p, r) |
|||
for i = 1 to p |
|||
print "proceso ", i, ":" |
|||
for j = 1 to r |
|||
input " " curr(i, j) |
|||
next j |
|||
print |
|||
next i |
|||
print "\n--- recursos m ximos para cada proceso ---" |
|||
dim maxReclam(p, r) |
|||
for i = 1 to p |
|||
print "proceso ", i, ":" |
|||
for j = 1 to r |
|||
input " " maxReclam(i, j) |
|||
next j |
|||
print |
|||
next i |
|||
print "\nRecursos totales asignados : "; |
|||
dim recAsigad(r) |
|||
for i = 1 to p |
|||
for j = 1 to r |
|||
recAsigad(j) = recAsigad(j) + curr(i, j) |
|||
next j |
|||
next i |
|||
for i = 1 to r |
|||
print recAsigad(i), " "; |
|||
next i |
|||
dim recDispon(r) |
|||
print "\nRecursos totales disponibles: "; |
|||
for i = 1 to r |
|||
recDispon(i) = maxRes(i) - recAsigad(i) |
|||
print recDispon(i), " "; |
|||
next i |
|||
dim ejecutando(p) |
|||
for i = 1 to p |
|||
ejecutando(i) = True |
|||
next i |
|||
contar = p |
|||
while contar <> 0 |
|||
seguro = False |
|||
for i = 1 to p |
|||
if ejecutando(i) then |
|||
ejecuta = True |
|||
for j = 1 to r |
|||
if (maxReclam(i,j) - curr(i,j) > recDispon(j)) then |
|||
ejecuta = False |
|||
break |
|||
end if |
|||
next j |
|||
if ejecuta then |
|||
print color("cya") "\n\nproceso ", i, " ejecut ndose." |
|||
ejecutando(i) = False |
|||
contar = contar - 1 |
|||
seguro = True |
|||
for j = 0 to r |
|||
recDispon(j) = recDispon(j) + curr(i,j) |
|||
next j |
|||
break |
|||
end if |
|||
end if |
|||
next i |
|||
if not seguro then |
|||
print color("red") "\nLos procesos est n en un estado inseguro." |
|||
break |
|||
end if |
|||
print color("gre") "El proceso est en un estado seguro." |
|||
print color("whi")"Recursos disponibles: ", |
|||
for i = 1 to r |
|||
print recDispon(i), " "; |
|||
next i |
|||
wend |
|||
print |
|||
end |
|||
</lang> |
|||
{{omit from|Blast}} |
{{omit from|Blast}} |