My friends, why this program no function in php4, just in php3? Pessoal, esse algoritmo é conhecido como Dijkstra, ele calcula o melhor caminho entre pontos( num grafo, por exemplo), mas nao consigo rodar ele no php4, so funciona no 3. Alguem sabe me dizer se há algo errado?
<? $neighbors[a] = array(b => 2, d => 3); $neighbors[b] = array(a => 2, c => 1, e => 4); $neighbors[c] = array(b => 1, f => 5); $neighbors[d] = array(a => 3, e => 2); $neighbors[e] = array(d => 2, b => 4, f => 1); $neighbors[f] = array(c => 5, e => 1); function dijkstra($neighbors, $start) { $closest = $start; while (isset($closest)) { $marked[$closest] = 1; reset($neighbors[$closest]); while(list($vertex, $distance) = each($neighbors[$closest])) { if ($marked[$vertex]) continue; $dist = $paths[$closest][0] + $distance; if (!isset($paths[$vertex]) || ($dist < $paths[$vertex][0])) { $paths[$vertex] = $paths[$closest]; $paths[$vertex][] = $closest; $paths[$vertex][0] = $dist; } } unset($closest); reset ($paths); while(list($vertex, $path) = each($paths)) { if ($marked[$vertex]) continue; $distance = $path[0]; if (($distance < $min) || !isset($closest)) { $min = $distance; $closest = $vertex; } } } return $paths; } $paths = dijkstra($neighbors, "$start"); while(list($vertex, $path) = each($paths)) echo "$vertex: ", implode(", ", $path), "\n"; ?>