I'm wondering if it's possible to find the minimum spanning tree from an ArrayList.
This is what I currently have:
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
public class GraphReading
{
public static void main(String[] args) throws FileNotFoundException
{
File f= new File("Bridges.txt");
Scanner sc= new Scanner(f);
ArrayList < ArrayList<Integer> > Vertices = new ArrayList<>();
while(sc.hasNext())
{
String Line = sc.nextLine();
String numbers[] = Line.split(" ");
ArrayList<Integer> List = new ArrayList<>();
for(int i=0;i < numbers.length ;i++)
{
if(numbers[i].equals("")==false)
List.add( Integer.parseInt( numbers [i]));
}
Vertices.add(List);
}
printAllvertices(Vertices);
}
public static void printAllvertices( ArrayList < ArrayList<Integer> > Vertices )
{
for(int i=0;i< Vertices .size();i++)
{
System.out.print("Vertice "+i+ " has ");
ArrayList<Integer> List = Vertices.get(i);
for(int j=0;j<List.size();j++)
{
System.out.print(List.get(j)+" ");
}
System.out.println();
}
}
}
I was thinking about just finding the minimum number from each of the vertices but I wasn't too sure that would necessarily work the way I wanted it too.