Visita BFS
ALGORITMO:
procedure BFS (G : grafo; s : integer);
var
Q: coda;
u,v: integer;
aus: LISTA;
begin
for u := 1 to maxnodi do begin
color[u] := 'w';
d[u] := -1;
pred[u] := 0;
end;
color[s] := 'g';
d[s] := 0;
initqueue(Q);
enqueue(s, Q);
while not isempty(Q) do
begin
aus:=g[u];
while (aus <> NIL) do begin
v := aus^.inf;
if (color[v] = 'w') then
begin
colore[v] := 'g';
d[v] := d[u] + 1;
pred[v] := u;
enqueue(v, Q);
end;
aus:= aus^.next
end;
dequeue(Q);
color[u] := 'b';
end;
end;
Torna a Programmazione e Lab.
Non ci sono commenti in questa pagina. [Scrivi commento]