package com.wang;
import java.util.Arrays;
public class Walkwaydemo {
public static void main(String[] args) {
// TODO Auto-generated method stub
final int No = 65535;// 表示不可以连接
char[] n = { 'P','A', 'B', 'C', 'D', 'E', 'F', 'G','H','I','.' };
//"P"为出发点;‘.’为中间站;"A-I"为客户点。
int[][] N = new int[n.length][n.length];//二维距离矩阵
N[0]=new int[]{No,5,8,7,No,4,12,9,12,6,5};
N[1]=new int[]{5,No,4,No,No,No,No,No,No,3,No};
N[2]=new int[]{8,4,No,3,No,No,No,No,No,No,No};
N[3]=new int[]{7,No,3,No,4,No,No,No,No,No,5};
N[4]=new int[]{No,No,No,4,No,3,No,No,No,No,2};
N[5]=new int[]{4,No,No,No,3,No,10,No,No,No,2};
N[6]=new int[]{12,No,No,No,No,10,No,4,7,No,No};
N[7]=new int[]{9,No,No,No,No,No,4,No,5,No,No};
N[8]=new int[]{12,No,No,No,No,No,7,5,No,9,No};
N[9]=new int[]{6,3,No,No,No,No,No,No,9,No,No};
N[10]=new int[]{5,No,No,5,2,2,No,No,No,No,No};
//创建 Graph对象
Graph graph = new Graph(n, N);
//测试, 看看图的邻接矩阵是否ok
graph.showGraph();
//测试迪杰斯特拉算法
graph.dsj(1);//P
graph.showDijkstra();
//graph.dsj(1);//P
}
}
class Graph {
private char[] n; // 顶点数组
private int[][] N; // 邻接矩阵
private VisitedVertex vv; //已经访问的顶点的集合
// 构造器
public Graph(char[] n, int[][] N) {
this.n = n;
this.N = N;
}
//显示结果
public void showDijkstra() {
vv.show();
}
// 显示图
public void showGraph() {
for (int[] link : N) {
System.out.println(Arrays.toString(link));
}