طباعة بيلمان فورد مسار تكرارا
-
14-11-2019 - |
سؤال
يمكنني حاليا إعداد خوارزمية Bellman Ford، وأنا أحاول طباعة المسار إلى تلك العقدة.خوارزمية الحالية هي مثل هذا: giveacodicetagpre.
وهذه هي الطريقة التي أطبعها بها.إنه متكرر ولكن كيف يمكنني إعداده حتى يكون تكراريا؟أنا حاليا الحصول على خطأ فائض المكدس. giveacodicetagpre.
المحلول
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.
لا تنتمي إلى StackOverflow