Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.IOException;
- import java.util.Scanner;
- public abstract class GraphIO implements Graph{
- /*
- * pre: filename is the name of a file containing a description of a
- graph (throws java.io.IOException)
- post: nodes and edges according to the description in
- file filename has been added to g.
- */
- static public void readFile(Graph g,String filename){
- try{
- File readFile = new File("src/egen.txt");
- Scanner myscanner=new Scanner(readFile);
- int n =myscanner.nextInt();
- for(int x=1; x<=n; x++){
- int i =myscanner.nextInt();
- int j=myscanner.nextInt();
- int k=myscanner.nextInt();
- g.addNode(i,j,k);
- }
- while (myscanner.hasNext()){
- int l =myscanner.nextInt();
- int m =myscanner.nextInt();
- int p =myscanner.nextInt();
- g.addEdge(l,m,p);
- }
- myscanner.close();
- }
- catch (IOException e){
- System.out.println("error in readFile ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement