小编sao*_*yne的帖子

随机生成边和顶点

我正在学习最小生成树,我遇到了这个问题并决定尝试一下......

在随机生成的 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)

java random algorithm graph kruskals-algorithm

0
推荐指数
1
解决办法
2701
查看次数

标签 统计

algorithm ×1

graph ×1

java ×1

kruskals-algorithm ×1

random ×1