Let's say we want to find the path between an origin and a destination in a graph. We'll want to return a LinkedList that lists vertices in order from the origin to the destination. To do this we’ll find the shortest path. In order to implement a getShortestPath method, we can take the following steps: Create a queue. This will tell you the next vertices to visit. Create a map. This will allow you to identify visited vertices, as well as trace your path backward. Add the origin vertex to your queue. Add the origin vertex to your map (try origin as the key, and null as the value). Then, while your queue is not empty (i.e. while you still have nodes not traversed): Retrieve & remove the next value from your queue. We’ll call it “currentVertex” for now. If currentVertex is your destination, you’ve finished. Calculate the path from origin to destination (using your map) and return it. If currentVertex is not your destination, retrieve th...
gadgets, technology, teaching, jobs, cameras, and other geek stuff