在下面代码的主函数中 的 MGragh.showGragh(gragh); 处为啥不能通过实体类调用静态方法。
import java.util.Arrays;
public class FloydAlgorithm {
public static void main(String[] args) {
char[] data = {'A','B','C','D','E','F','G'};
int[][] weight = {{10000,5,7,10000,10000,10000,2},
{5,10000,10000,9,10000,10000,3},
{7,10000,10000,10000,8,10000,10000},
{10000,9,10000,10000,10000,4,10000},
{10000,10000,8,10000,10000,5,4},
{10000,10000,10000,4,5,10000,6},
{2,3,10000,10000,4,6,10000}};
MGragh gragh = new MGragh(data, weight);
MGragh.showGragh(gragh);
FloydAlgorithm floydAlgorithm = new FloydAlgorithm();
floydAlgorithm.floyd(gragh);
MGragh.showGragh(gragh);
}
public void floyd(MGragh gragh) {
int verx = gragh.verx;
int i,j,k;
for(k=0;k<verx;k++) {
for(i=0;i<verx;i++) {
for(j=0;j<verx;j++) {
if(gragh.weight[i][j] > (gragh.weight[i][k] + gragh.weight[k][j])) {
gragh.weight[i][j] = (gragh.weight[i][k] + gragh.weight[k][j]);
}
}
}
}
}
}
class MGragh {
int verx;//表示图的节点个数
char[] data ;//存放节点数据
int[][] weight;//存放边,就是我们的邻接矩阵
public MGragh(int verx) {
data = new char[verx];
weight = new int[verx][verx];
}
public MGragh(char[] data, int[][] weight) {
this.verx = data.length;
this.data = new char[this.verx];
this.weight = new int[this.verx][this.verx];
int i,j;
for (i=0;i<this.verx;i++) {
this.data[i] = data[i];
for(j=0;j<verx;j++) {
this.weight[i][j] = weight[i][j];
}
}
}
public static void showGragh(MGragh gragh) {
for(int[] row : gragh.weight) {
System.out.println(Arrays.toString(row));
}
}
}