r/javahelp • • Jun 02 '20

Dijkstra using PriorityQueue and Collections

I have problem implementing Dijkstra's algorithm in Java using PriorityQueue. The program is not checking all the nodes . PLEASE I NEED HELP FIXING THIS. here is the code :

https://hasteb.in/amuhemig.cs

0 Upvotes

4 comments sorted by

1

u/[deleted] Jun 02 '20

Help with what exactly? What solution have you tried? Or did you just want someone to send you a solution?

0

u/Shylamo Jun 02 '20

I have already tried, and I was told to try to work with Priority Queue instead of ArrayList but I keep getting this error :

Exception in thread "main" java.lang.ClassCastException: successeur.noeud cannot be cast to java.lang.Comparable

`at java.util.PriorityQueue.siftUpComparable(Unknown Source)`

`at java.util.PriorityQueue.siftUp(Unknown Source)`

`at java.util.PriorityQueue.offer(Unknown Source)`

`at java.util.PriorityQueue.add(Unknown Source)`

`at successeur.dijkstra1.chemin_court(`[`dijkstra1.java:67`](https://dijkstra1.java:67)`)`

`at successeur.testSuc.main(`[`testSuc.java:45`](https://testSuc.java:45)`)`

1

u/[deleted] Jun 02 '20

Error messages literally tell you what and where the error is. All you gotta do is read what it says.

1

u/Robyt3 Jun 02 '20

Try doing the things that bring you closer to your goal and don't do the wrong things.

Also try a subreddit that's actually about .cs files (like /r/csharp or /r/cheesesandwich).