Advertisement
FahimFaisal

AdjacencyList

Oct 8th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3.  
  4. public class Text_Read {
  5.     public static int [][] adjMatrix;
  6.             /**
  7.          * @param args the command line arguments
  8.          */
  9.         public static void main(String[] args) {
  10.         try{
  11.             Scanner sc=new Scanner(new File("E:\\aa.txt"));
  12.             String [] spaceSplit;    
  13.            
  14.             String temp1=sc.nextLine();
  15.             Integer v=Integer.parseInt(temp1);
  16.            
  17.             String temp2=sc.nextLine();
  18.             Integer e=Integer.parseInt(temp2);
  19.            
  20.             adjMatrix=new int[v][v];
  21.             while(sc.hasNext())
  22.             {
  23.             String line=sc.nextLine();
  24.             spaceSplit=line.split(" ");
  25.             String tempo1=spaceSplit[0];
  26.             String tempo2=spaceSplit[1];
  27.            
  28.             int x=Integer.parseInt(tempo1);
  29.             int y=Integer.parseInt(tempo2);
  30.            
  31.             adjMatrix[x][y]=1;
  32.             }
  33.            
  34.             for(int i=0;i<v;i++) {
  35.                 for(int j=0;j<v;j++) {
  36.                     System.out.print(adjMatrix[i][j]+",");
  37.                 }
  38.                 System.out.println();
  39.             }
  40.  
  41. }
  42.         catch(Exception  e){
  43.             //System.out.println(e);
  44.             e.printStackTrace();
  45.         }
  46.         }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement