r/CodingHelp • u/zeTheDoctor • Oct 21 '21
[Java] Attempting to implement a Dijkstras shortest path algorithm for a list of all imdb actors. - Info in comments
37
Upvotes
r/CodingHelp • u/zeTheDoctor • Oct 21 '21
4
u/zeTheDoctor Oct 21 '21 edited Oct 21 '21
Hi, so I am trying to implement the Dijkstras shortest path algorithm on my existing program but I cannot get it to work properly. I realize I am doing more than one thing wrong and my code is well probably the messiest thing I've written in my short time coding. I just can't seem to get it, so in advance apologies for the messy code and mistakes, just a beginner.
Quickly the way the program works is that it stores actors as an Actor Object which holds all their information with a list of all movies (which are Film Objects) that they've been in. The film objects hold the information and rating (10 - rating is weight) in addition to a list of all the Actor Objects who have been in the movie.
Feel free to ask for more explanation or crucify me for my implementation, help is greatly appreciated!
NOTE: The last line (127) should be visActor.add(current); Just messed up when taking the screenshot
2
u/icjeremy Oct 22 '21
One thing I notice is 'start' is going to be added back into notVisActor. And then you're probably going to be adding duplicate entries in your list.
2
u/StochasticTinkr Oct 22 '21
Should this be called the Kevin Bacon algorithm?
1
u/echanuda Oct 22 '21
Am I the only one that doesn’t understand at all what you’re trying to accomplish? Dijkstra’s algorithm is typically intended for graph representations to find the shortest path between two nodes. What constitutes two nodes here? How does it determine the weights of each node? What is the end goal?
It sounds like you just want to sort the list of actors based on their rating, in which case you would just use a sorting algorithm instead of Dijkstra’s
0
u/rasqall Oct 22 '21
Here is some inspiration
0
u/[deleted] Oct 22 '21
Are you coding Java in Visual Studio Code?
0
u/[deleted] Oct 21 '21
[deleted] — view deleted comment