Dijkstra算法的Java实现_第1页
免费预览已结束,剩余4页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、dijkstra算法的java实现dijkstra算法的java实现 1 package main.java; 2 3 import main.java.utils.graphutil; 4 5 import java.util.arraydeque; 6 import java.util.list; 7 import java.util.queue; 8 9 10 /* 11 * tme 2019/9/12 10:40 12 * author chenhaisheng 13 * email:ecjutsbs 14 */ 15 public class dijkstratest 16 17 /

2、邻接矩阵的表示 18 public final static double graph_distance = graphutil.getdijkstragraph(); 19 20 /起点到某节点的暂时最短距离 21 public static double distance = new doublegraph_distance.length; 22 23 /某节点的前驱节点 24 public static int pre = new intgraph_distance.length; 25 26 static int originindex = 0, toindex = 4; 27 28

3、29 public static void main(string args) 30 31 init(); 32 finddijkstrashortestpath(); 33 34 35 /* 36 *初始化distance pre 37 */ 38 public static void init() 39 40 for (int i = 0; i queue = new arraydeque(); 57 58 /起始,将起始节点添加到queue 59 queue.add(originindex); 60 61 while (queue.size() != 0) 62 63 integer c

4、urrentindex = queue.poll(); 64 65 /猎取当前节点的out-edges 66 list neighbours = getneighbours(currentindex); 67 68 for (int i = 0; i path = new arraydeque(); 97 98 path.push(to); 99 100 int preindex = preto;101 while (preindex != from) 102 path.push(preindex);103 preindex = prepreindex;104 105106 path.push

5、(from);107108 while (!path.isempty() 109 system.out.print(path.poll() + (path.size() > 0 ? "->" : " ");110 111 system.out.println(" ");112 113114115 /猎取当前节点全部的out-edges116 public static list getneighbours(int index) 117118 list res = new arraylist();119120 /距离不为double.max_value,代表与当前节点连通121 for (int i = 0; i 9 10 public static double getdijkstragraph()11 double max=double.max_value;12 double graph=13 max,5,max,7,15,14 max,max,5,max,max,15 max,max,max,ma

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论