2013-11-24 47 views
1
import java.util.Scanner; 
import java.io.File; 
import java.io.FileNotFoundException; 
import java.util.StringTokenizer; 

public class Graph1 { 
    public static void main(String[] args) throws FileNotFoundException { 
     int linecount = 0, ec = 0; 
     int nbin = 0, cbin = 0; 
     int[][] data = new int[6][6]; 
     String e = "e"; 
     Scanner sc = new Scanner(System.in); 
     System.out.print("Enter input file name: "); 
     String newfile = sc.nextLine() + ".txt"; 
     File file = new File(newfile); 
     Scanner scan = new Scanner(file); 
     while ((scan.hasNext())) { 
      StringTokenizer t = new StringTokenizer(scan.nextLine()); 
      if(t.nextToken().equals(e)) { 
       ec++;System.out.print("ec.." + ec); 
       nbin = Integer.parseInt(t.nextToken()); 
       cbin = Integer.parseInt(t.nextToken()); 
       data[nbin][cbin] = 1; 
      } 
     } 

輸入文件是:從文件創建鄰接表

jjjjjjjjj 
e 1 3 
e 2 5 
e 3 4 
e 4 1 
e 5 3 

我想從文件entries.my代碼創建鄰接表給出了相鄰matrix.i聽說有對鄰接表的特定功能在java請幫助

回答

0

你可能要開始下載Open Data Structures。如果你點擊標有java sources的鏈接,你將得到一個存檔文件,其中包含幾個數據結構的源文件(和已編譯的類文件)。其中包括一個AdjcencyLists的java實現。