Assuming everything else works as expected, is the following a correct - but not the most efficient way - of implementing Dijkstra algorithm? Because I have tested it on several examples and it gives correct result. But I can't imagine Dijkstra is that simple.  public static void FindShortestPath(Node source, Directed graph)    {        if(source==null)        {            System.err.println(Source doesn't exist.);            System.exit(0);        }       source.setCost(0); // all nodes are initialized with cost=Double.Max_VALUE when first created.       PriorityQueue<Node> pq=new PriorityQueue<>(); // Node implements comparable according to cost       for(Node node:graph.getAdj().keySet()) // get all nodes           pq.add(node);         while(!pq.isEmpty())         {            Node u=pq.poll(); // the minimum            List<Node> neighbours=graph.getAdj().get(u); // get the minimum direct successors            for(Node v:neighbours)             {                 if(v.getCost()>(u.getCost()+(graph.getCost(u, v)))) // if there is a cheaper one                {                    v.setCost(u.getCost()+graph.getCost(u, v)); // change its cost                    pq.remove(v);  //remove it                    pq.add(v);  // add it again                }             }        }        }
Dijkstra's algorithm
java;graph;pathfinding