上传者: u013183000
|
上传时间: 2022-11-18 09:02:44
|
文件大小: 2KB
|
文件类型: JAVA
java单源最短路径(贪心算法)
public class TheShortestWay {
static int MAX_SIZE = 6;
public static void dijkstra(int v, float[][] a, float[] dist, int[] prev) {
int n = dist.length - 1;
if (v < 1 || v > n)
return;
boolean[] s = new boolean[n + 1];
for (int i = 1; i <= n; i++) {
dist[i] = a[v][i];
s[i] = false;
if (dist[i] == Float.MAX_VALUE)
prev[i] = 0;
else
prev[i] = v;