r/programminghomework • u/luke2thebun • Dec 02 '16
BFS to Dijkstras algorithm..
I was given Breadthfirstsearch code and have been tasked with changing it to depth first search and then to Dijkstras algorithm with start Vertex : (id : 28776 ) to the vertex (id : 47002). I'll be honest with you the code I've been given is way over my head with its use of pointers and queues as I am not a Computer science student. Ive managed to get depth first search working but not luck on dijkstras, here's some relevant code:
Here is a link to a google drive directory ( I know I should be using Github but I'm kind of a caveman when it comes to things like this.. ) https://drive.google.com/drive/folders/0B-91BnP5bq1ZYWZTRlhyaGVHb2c
Pastebin: sorry guys http://pastebin.com/BZuiW21S
View all comments
Show parent comment
2
u/thediabloman Dec 06 '16
You need to first understand the Dijkstras Algorithm. Fortunately there are tons of videos that will try and explain this to you.
In your implementation you need a SortedQueue as your SearchQueue. When you pop something from the queue it must be the thing that is closest to your original vertex. Then you add all of that vertex neighbours to the queue with the total path length to get there as the "sort value".