简体   繁体   English

插入3D arraylist

[英]Insertion in 3D arraylist

I have created 3D ArrayList. 我创建了3D ArrayList。 I know initialization is done using this code 我知道初始化是使用此代码完成的

ArrayList<ArrayList<ArrayList>> ll=new ArrayList<ArrayList<ArrayList>>();  
for(int j=0;j<n;j++){
    ll.add(new ArrayList(new ArrayList()));
}

But I dont know how insert values in it. 但是我不知道如何在其中插入值。 I am familiar with 2D arraylist in which inserting value b at a index is done using 我熟悉2D arraylist,其中在索引处插入值b是使用

ll.get(a).add(b);

but I dont know how to insert value into 3D arrayList. 但我不知道如何将值插入3D arrayList。

I am solving question http://www.spoj.com/problems/BENEFACT/ 我正在解决问题http://www.spoj.com/problems/BENEFACT/
in which I think longest distance in tree is the answer. 我认为其中最长的距离就是答案。 I used 3D ArrayList here, 2dimension to store connection of places and 3rd dimension to store distance 我在这里使用3D ArrayList,2dimension来存储位置的连接,而在3d维度上存储距离

Is this correct approach? 这是正确的方法吗? Is Any other approach possible in which solution is obtained easier than using 3d ArrayList? 是否有其他方法比使用3d ArrayList更容易获得解决方案?

I think if you want to access an object at index i,j,k you can do it by 我认为如果您要访问索引i,j,k的对象,可以通过

ll.get(i).get(j).get(k)

Or 要么

ll.get(i).get(j).add(k,newObject)

Depending on your need, you probably don't want that. 根据您的需要,您可能不希望这样做。 I didn't read the full description of the problem to solve (the link), but you just need 6 points in 3D space. 我没有阅读要解决的问题的完整描述(链接),但是您只需要在3D空间中放置6个点即可。

I'd suggest creating a Point3D class with x , y , and z , and then just a simple List<Point3D> . 我建议使用xyz创建一个Point3D类,然后创建一个简单的List<Point3D>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM