Codice:
DFS(Albero):
Foglie <- 0; //insieme vuoto
DFS_visit(Albero[radice], Foglie);
end
DFS_visit(v, S):
if Adj[v] == 0 then
S <- S unione v
return;
for w in Adj[v] do
if Adj[w] == 0 then S <- S unione w;
else DFS_visit(w, S);
end
end
Al termine dell' algoritmo S conterrà le foglie dell'albero.
Probabilmente si può fare meglio.
__________________
AMD PII x4 955 BE | Sapphire HD4850 Vapor-X 1 GB | Samsung SpinPoint F1 500GB | Samsung EcoGreen F4 2TB
Gigabyte GA-MA790FXT-UD5P | Fractal Design Define R3 USB3.0 Titanium Grey | CORSAIR 650W CMPSU-650TX
Noctua U12P SE2 | 2 x 2GB Kingston 1333 MHz | Samsung SyncMaster P2450 | Samsung SyncMaster T200