Guest User

Untitled

a guest
Jul 20th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.29 KB | None | 0 0
  1. public static ArrayList<node> loadNode(String path) throws IOException
  2.     {
  3.         int size = getSizeNode(path);
  4.         int[][] vert = loadVert(path, size);
  5.         ArrayList<node> nodes = new ArrayList<node>();
  6.         //create nodes 1 through 1000...something only need about 600
  7.         for(int i = 0; i < size; i++)
  8.         {
  9.             node n = new node(i);
  10.             nodes.add(n);
  11.         }
  12.         //create the connections
  13.  
  14.         BufferedReader in = new BufferedReader(new FileReader(path));
  15.        
  16.         //for(int i = 0; i < size-1; i++)
  17.         String str = new String();
  18.         while((str = in.readLine()) != null)
  19.         {
  20.             Scanner scn = new Scanner(str);
  21.             int one = scn.nextInt()-1;
  22.             int two = scn.nextInt()-1;
  23.             int three = scn.nextInt()-1;
  24.            
  25.             node cur1 = nodes.get(one);
  26.             node cur2 = nodes.get(two);
  27.             node cur3 = nodes.get(three);
  28.            
  29.             if(!cur1.getConnected().contains(cur2))
  30.                 cur1.getConnected().add(cur2);
  31.             if(!cur1.getConnected().contains(cur3))
  32.                 cur1.getConnected().add(cur3);
  33.                
  34.             if(!cur2.getConnected().contains(cur1))
  35.                 cur2.getConnected().add(cur1);
  36.             if(!cur2.getConnected().contains(cur3))
  37.                 cur2.getConnected().add(cur3);
  38.            
  39.             if(!cur3.getConnected().contains(cur2))
  40.                 cur3.getConnected().add(cur2);
  41.             if(!cur3.getConnected().contains(cur1))
  42.                 cur3.getConnected().add(cur1);
  43.            
  44.         }
  45.         return nodes;
  46.     }
Add Comment
Please, Sign In to add comment