1. 图的表示:给定图数据文件(tinyG.txt),计算得到图的邻接矩阵,并把邻接矩阵保存到文件(tinyG_matrix.txt)中。类名:GraphRepresentation。摘自《Algorithms, 4th Edition》P522。博文标题:第四周作业——图的表示
package test;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;
public class aa {
int v ;
int e ;
int[][] matrix;
public aa (int v,int e) {
this.v = v;
this.e = e;
matrix = new int[v][e];
}
public void addEdge(int v1,int v2) {
matrix[v1][v2] = 1;
matrix[v2][v1] = 1;
}
public int[][] getAdjacentMatrix(){
return matrix;
}
public static void main(String[] args) throws FileNotFoundException{
String path = "C:/Users/玲/Desktop/";
File file = new File(path+"tinyG.txt");
Scanner scan = new Scanner(file);
PrintWriter out = new PrintWriter(path+"tinyG_Matrix.txt");
int v = scan.nextInt(); //读取第一行是顶点的个数
int e = scan.nextInt(); //读取第二行是边的个数
aa graph = new aa(v,e);
for(int i=0;i