⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readfile.java

📁 This code implements the shortest path algorithm via the simple scheme and fibonacci heap data struc
💻 JAVA
字号:


import java.io.*;
import java.util.StringTokenizer;

public class ReadFile {	
	public AdjGraph graph;
	public int linect=-1;  
	//count the number of lines in the data file
	
	public ReadFile(String filename){ 
		graph = new AdjGraph(1000);
	    int readin[]=new int[3];
	 
		try
		{   //read from file and store the data into a adjacent graph G
			BufferedReader inputStream =
				new BufferedReader(new FileReader(filename));
			String line = null;
			line = inputStream.readLine();
			while(line.compareTo("*")!=0){
				 linect++;
				 int i=0;
				 StringTokenizer T = new StringTokenizer(line);
			     while (T.hasMoreTokens()){
			    	 readin[i]=Integer.valueOf(T.nextToken()).intValue();
			         i++;
			     }
			     if (i<2) graph.setSource(readin[0]);
			     else graph.addNode(readin[0], readin[1], readin[2]);
			     line = inputStream.readLine();
			}
		}
		catch(FileNotFoundException e)
		{
			System.out.println("Data file was not found");
			System.out.println("or could not be opened.");
		}
		catch(IOException e)
		{
			System.out.println("Error reading from file.");
		}
	}
	
	public AdjGraph getGraph(){
		//return the graph
		return graph;
	}
}




⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -