Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.01 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.IOException;
  3. import java.util.Scanner;
  4.  
  5. public abstract class GraphIO implements Graph{
  6.    
  7.     /*
  8.      *  pre:  filename is the name of a file containing a description of a
  9.         graph (throws java.io.IOException)
  10.  
  11.         post: nodes and edges according to the description in
  12.         file filename has been added to g.
  13.      */
  14.    
  15.    
  16.    
  17.     static public void readFile(Graph g,String filename){
  18.  
  19.    
  20.        
  21.         try{
  22.             File readFile = new File("src/egen.txt");
  23.            
  24.             Scanner myscanner=new Scanner(readFile);
  25.             int n =myscanner.nextInt();
  26.             for(int x=1; x<=n; x++){
  27.                 int i =myscanner.nextInt();
  28.                 int j=myscanner.nextInt();
  29.                 int k=myscanner.nextInt();
  30.                 g.addNode(i,j,k);
  31.    
  32.             }
  33.             while (myscanner.hasNext()){
  34.                 int l =myscanner.nextInt();
  35.                 int m =myscanner.nextInt();
  36.                 int p =myscanner.nextInt();
  37.                 g.addEdge(l,m,p);
  38.             }
  39.             myscanner.close();
  40.         }
  41.         catch (IOException e){
  42.             System.out.println("error in readFile ");
  43.            
  44.         }
  45.            
  46.        
  47.        
  48.        
  49.        
  50.     }
  51.    
  52.    
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement