文档介绍:求最短路径: V2 4v3 325 V011V5 532 V13V4 JAVA 代码实现: public class DataTest { public static int INFINITY =90000; public static Map<String,Vertex> vertexMap =new HashMap<String,Vertex>(); static class Edge{ public Vertex dest ; public double cost ; public Edge(Vertex d, double c){ this .dest =d; this .cost =c; }}static class Vertex parable<Vertex>{ public String name ; public List<Edge> adj ; public double dist ; public Vertex prev ; public int scratch ; public boolean visited ; public Vertex(String nm){ this .name =nm; adj =new ArrayList<Edge>(); reset(); }public void reset(){ visited =false ; dist =DataTest. INFINITY ; }public pareTo(Vertex o) { double c=o. dist ; return dist <c?-1: dist >c?1:0; }}public static void dijkstra(String startName){ PriorityQueue<Vertex> pq =new PriorityQueue<Vertex>(); // 该队列以权值升序排列,因为 Vertex parable 接口 Vertex start =vertexMap .get(startName); start. dist =0; for (Vertex v: vertexMap .values()) (v); int seenNum =0; while (!()&&seenNum <vertexMap .size()){ Vertex v=(); System. out .println( "v0---->" +v. name +":." +v. dist ); if (v. scratch != 0) continue ;v. scratch =1; seenNum++; for (Edge e:v. adj ){ Vertex w=e. dest ; double v_to_w =e. cost ; if (w. dist >v. dist +v_to_w){ w. dist =v. dist +v_to_w; w. prev =v; (w); // 出队 (w); // 按优先级插在队头,先插入的在队头, 依次往后}}}while (() != null ){ System. out .println(());