سؤال

يمكنني حاليا إعداد خوارزمية 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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top