第四周作业——图的表示
来源:互联网 发布:c# lambda表达式 java 编辑:程序博客网 时间:2024/06/16 22:29
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedList;
public class GraphRepresentation {
public static void main(String[] args) {
File file = new File("C:\\tinyG.txt");
private ArrayList vertexList;
private int[][] edges;
private int numOfEdges;
System.out.println("结点个数是:"+graph.getNumOfVertex());
System.out.println("边的个数是:"+graph.getNumOfEdges());
graph.Edge(0, 1);
System.out.println("删除<V1,V2>边后...");
System.out.println("结点个数是:"+graph.getNumOfVertex());
System.out.println("边的个数是:"+graph.getNumOfEdges());
edges=new int[n][n];
vertexList=new ArrayList(n);
numOfEdges=0;
}
public int getNumOfVertex(){
return vertexList.size();
}
public int getNumOfEdges()
{
return numOfEdges;
}
public Object getValueByIndex(int i)
{
return vertexList.get(i);
}
public int getWeight(int v1,int v2)
{
return edges[v1][v2];
}
public void Vertex(Object vertex)
{
vertexList.add(vertexList.size(),vertex);
}
public void Edge(int v1,int v2,int weight){
edges[v1][v2]=weight;
numOfEdges++;
}
public void Edge(int v1,int v2)
{
edges[v1][v2]=0;
numOfEdges--;
}
public int getFirstNeighbor(int index)
{
for(int j=0;j<vertexList.size();j++)
{
if (edges[index][j]>0)
{
return j;
}
}
return -1;
}
public int getNextNeighbor(int v1,int v2)
{
for (int j=v2+1;j<vertexList.size();j++)
{
if (edges[v1][j]>0)
{
return j;
}
}
return -1;
}
}
try {
FileReader fr = new FileReader(file);
BufferedReader br = new BufferedReader(fr);
try {
String s, s2 = new String();
while ((s = br.readLine()) != null) {
s2 += s + "\n ";
}
br.close();
System.out.println(s2);
} catch (IOException e) {
e.printStackTrace();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedList;
public class GraphRepresentation {
public static void main(String[] args) {
File file = new File("C:\\tinyG.txt");
private ArrayList vertexList;
private int[][] edges;
private int numOfEdges;
System.out.println("结点个数是:"+graph.getNumOfVertex());
System.out.println("边的个数是:"+graph.getNumOfEdges());
graph.Edge(0, 1);
System.out.println("删除<V1,V2>边后...");
System.out.println("结点个数是:"+graph.getNumOfVertex());
System.out.println("边的个数是:"+graph.getNumOfEdges());
edges=new int[n][n];
vertexList=new ArrayList(n);
numOfEdges=0;
}
public int getNumOfVertex(){
return vertexList.size();
}
public int getNumOfEdges()
{
return numOfEdges;
}
public Object getValueByIndex(int i)
{
return vertexList.get(i);
}
public int getWeight(int v1,int v2)
{
return edges[v1][v2];
}
public void Vertex(Object vertex)
{
vertexList.add(vertexList.size(),vertex);
}
public void Edge(int v1,int v2,int weight){
edges[v1][v2]=weight;
numOfEdges++;
}
public void Edge(int v1,int v2)
{
edges[v1][v2]=0;
numOfEdges--;
}
public int getFirstNeighbor(int index)
{
for(int j=0;j<vertexList.size();j++)
{
if (edges[index][j]>0)
{
return j;
}
}
return -1;
}
public int getNextNeighbor(int v1,int v2)
{
for (int j=v2+1;j<vertexList.size();j++)
{
if (edges[v1][j]>0)
{
return j;
}
}
return -1;
}
}
try {
FileReader fr = new FileReader(file);
BufferedReader br = new BufferedReader(fr);
try {
String s, s2 = new String();
while ((s = br.readLine()) != null) {
s2 += s + "\n ";
}
br.close();
System.out.println(s2);
} catch (IOException e) {
e.printStackTrace();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
0 0
- 第四周作业—图的表示
- 第四周作业—图的表示
- 第四周作业—图的表示
- 第四周作业—图的表示
- 第四周作业——图的表示
- 第四周作业——图的表示
- 第四周作业——图的表示(GraphRepresentation)
- 第四周作业——图的表示
- 第四周作业——图的表示
- 第四周作业——图的表示
- 第四周作业——图的表示
- 第四周作业——图的表示
- 第四周作业——图的表示
- 第四周作业——图的表示
- 第四周作业——图的表示
- 第四周作业——图的表示
- 第四周作业——图的表示
- 第四周作业——图的表示
- 学习计划
- servlet和jsp之间的相互传值
- wsdl解析
- Camshift注释版
- 【WebGoat笔记】之五 --- Injection Flaws
- 第四周作业——图的表示
- js中window.open()的所有参数详解
- 扫雷核心算法
- 影响排名的十大因素
- 使用SQL语句创建基本数据库
- Grabcut标注解析
- Linux模拟按键输入
- 内链对seo的作用
- Java一个真正面向对象的语言