第五周作业——有向图邻接表表示及反向图构造

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;

class Vertex{
	int firstNode;//边的起点
	Edge firstEdge;//以firstNode为起点的第一条边
	public Vertex(int firstNode){
		this.firstNode = firstNode;
		firstEdge = null;
	}	
}
class Edge{
	int end;//边的终点    
	Edge next;//具有同一起点的下一条边  
	public Edge(int end){  
		this.end = end;  
		next=null;  
	} 
}
public class GraphReverse {

	/**
	 * @param args
	 */
	int adjListNum;//顶点数目
	Vertex adjList[];//正向邻接表顶点数组
	Vertex adjListOppsite[];//反向邻接表顶点数组
	
	public  GraphReverse(int adjListNum, Vertex adjList[], Vertex adjListOppsite[]) {
		this.adjListNum = adjListNum;	
		this.adjList = adjList;
		this.adjListOppsite = adjListOppsite;
	}
	public static void main(String[] args) {	
		int verNum,arNum;//顶点数与边数
		try{
			FileReader f = new FileReader("C:/Users/Y470/Desktop/tinyDG.txt");
			BufferedReader br = new BufferedReader(f);
			
			String readStr = br.readLine().trim();//读取第一行
			verNum = Integer.parseInt(readStr);
			readStr = br.readLine().trim();//读取第二行
			arNum = Integer.parseInt(readStr);
			
			//定义两个临时定点表数组(指向正向与反向)
			Vertex temporaryVer[] = new Vertex[verNum];
			Vertex temporaryVerO[] = new Vertex[verNum];
			
			//正向反向邻接表初始化
			for(int i=0;i
第五周作业——有向图邻接表表示及反向图构造_第1张图片

你可能感兴趣的:(算法)