Frage

Ich habe derzeit einen Bellman-Ford-Algorithmus eingerichtet und ich versuche, den Pfad zu diesem Knoten zu drucken.Mein aktueller Algorithmus ist so: generasacodicetagpre.

Und so drucke ich es aus.Es ist rekursiv, aber wie würde ich es einrichten, damit es iterativ ist?Ich bekomme derzeit einen Stapelüberlauffehler. generasacodicetagpre.

War es hilfreich?

Lösung

You have your parent backlinks in path. So if you just follow those links back inside a while loop until you the source, you'll have visited the path in reverse. So as you are visiting each node in a path, put it into a simple resizable container (ArrayList works well in Java), and then reverse it and print it out when you are done.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top