Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 转置一个图(2D数组),其中图[i]。长度=i度_Java_Arrays_Multidimensional Array_Graph_Transpose - Fatal编程技术网

Java 转置一个图(2D数组),其中图[i]。长度=i度

Java 转置一个图(2D数组),其中图[i]。长度=i度,java,arrays,multidimensional-array,graph,transpose,Java,Arrays,Multidimensional Array,Graph,Transpose,我必须转置一个图,它被实现为一个2D数组(对于第一维度中的每个元素,第二维度的大小是可变的)。我的代码中的图形如下所示: new GraphImpl(new int [] [] { {1,3,4,5}, //this is knot 0, which has a edge to 1, 3, 4, 5 {5,3}, //this is knot 1, which has a edge to 5, 3 {}, //this

我必须转置一个图,它被实现为一个2D数组(对于第一维度中的每个元素,第二维度的大小是可变的)。我的代码中的图形如下所示:

new GraphImpl(new int [] [] {
    {1,3,4,5},      //this is knot 0, which has a edge to 1, 3, 4, 5
    {5,3},          //this is knot 1, which has a edge to 5, 3
    {},             //this is knot 2, which has no edges
    {5},
    {1,5},
    {},
    {5},
    {1,4,5,6}
})
{},
{0,4,7},
{},
{0,1},
{0,7},
{0,1,3,4,6,7},
{7},
{}
问题是:如何获得转置图的数组第二维的大小

转置图应如下所示:

new GraphImpl(new int [] [] {
    {1,3,4,5},      //this is knot 0, which has a edge to 1, 3, 4, 5
    {5,3},          //this is knot 1, which has a edge to 5, 3
    {},             //this is knot 2, which has no edges
    {5},
    {1,5},
    {},
    {5},
    {1,4,5,6}
})
{},
{0,4,7},
{},
{0,1},
{0,7},
{0,1,3,4,6,7},
{7},
{}

你已经试过什么了?嗯,还没什么,因为我不知道从哪里开始。。。我已经用二项式堆“转置”了图(我把邻域的索引作为优先级,结源作为数据,所以当我调用二项式堆类的extract minimum函数(此时代码并不重要)时,我得到了所有结,它们的邻域按升序排列。)但是,我不知道,如何为转置图初始化数组,因为我不知道如何为数组第一维中的每个元素实现数组第二维的可变大小。有很多方法可以做到这一点。例如,迭代两次以获取阵列的连接节点。一次仅用于计数和获取数组维度,第二次用于获取节点。或者使用
列表
代替数组,然后在完全填充后将其转换为数组。我不希望使用ArrayList,因为我必须从java.util中导入它,我不知道是否允许这样做。我考虑过双重迭代,但我不知道该如何工作。我可以迭代并执行g[i]=newint[neights]吗?!我试过了,效果就是这样,非常感谢