我正在学习最小生成树,我遇到了这个问题并决定尝试一下......
在随机生成的 100 个顶点和 800 个边的有向图网络上实现最小生成树算法
public static int[][] getRandomArray(int n){
int[][] a = new int[n][n];
Random r = new Random();
for(int i = 0; i < a.length; i++){
for(int j = 0; j < a[i].length; j++){
a[i][j] = r.nextInt();
}
}
return a;
}
public static void main (String [] args)
{
int x[];
//TreeSet is used to sort the edges before passing to the algorithm
TreeSet<Edge> edges = new TreeSet<Edge>();
Random random = new Random();
edges.add(new Edge("0", "1", …
Run Code Online (Sandbox Code Playgroud)