第四周__图的表示
来源:互联网 发布:mac光影 编辑:程序博客网 时间:2024/05/22 10:37
- package bbb;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.io.IOException;
- import java.io.PrintWriter;
- public class GraphRepresentation {
- /**
- * 计算得到图的邻接矩阵,并把邻接矩阵保存到文件
- */
- static int arc[][];
- static int vertextNum;
- static int arcNum;
- static int vartex[];
- public static void main(String[] args) {
- String path1="src/tinyG.txt";
- String path2="src/tinyGResult.txt";
- try {
- FileReader read=new FileReader(new File(path1));
- BufferedReader reader=new BufferedReader(read);
- PrintWriter out=new PrintWriter(new File(path2));
- String line="";
- int index=1;
- while((line=reader.readLine())!=null){
- if(index==1){
- vertextNum=Integer.parseInt(line.trim());
- index++;
- continue;
- }else if(index==2){
- arcNum=Integer.parseInt(line.trim());
- index++;
- continue;
- } else if(index==3){
- arc=new int[vertextNum][arcNum];
- index++;
- continue;
- }
- addEadge(line);
- index++;
- }
- for(int i=0;i<vertextNum;i++){
- for(int j=0;j<vertextNum;j++){
- out.print(arc[i][j]+"\t");
- System.out.print(arc[i][j]+"\t");
- }
- out.flush();
- out.println();
- System.out.println();
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public static void addEadge(String line){
- String []result=line.trim().split(" ");
- int v1=Integer.parseInt(result[0]);
- int v2=Integer.parseInt(result[1]);
- for(int i=0;i<arcNum;i++){
- arc[v1][v2]=1;
- arc[v2][v1]=1;
- }
- }
- }
0 0
- 第四周__图的表示
- 第四周 图的表示
- 第四周:图的表示
- 第四周——图的表示
- 第四周作业 -- 图的表示
- 第四周作业--图的表示
- 第四周作业—图的表示
- 第四周作业---图的表示
- 第四周作业-图的表示
- 第四周作业-图的表示
- 第四周作业---图的表示
- 第四周作业—图的表示
- 第四周作业--图的表示
- 第四周作业—图的表示
- 第四周java作业,图的表示
- 1114第四周 图的表示
- 第四周作业—图的表示
- 第四周作业,图的表示
- 黑马程序员-----java中你必须掌握的线程技术一DAY15总结
- makefile
- [linux命令] 在某指定时间执行命令 at
- delegate和Notification的区别
- 第四周作业(1)
- 第四周__图的表示
- WPF TabControl控件禁止切换
- N-gram模型(基于词表)
- 解决eclipse更新安装插件慢的方法
- 你必有一样拿得出手?
- 通过IP和socket获取对方的MAC地址
- 小公司怎样招到技术型大神?
- 三星苹果好日子到头 智能机进入大众消费时代
- 面子的价值?