谁可以帮助我使用递归创建动态多维数组。 我需要创建一个具有数组深度和子数
的函数阵列的深度可能有不同的大小
class Item {
public int id;
public Map<Integer, Item>[] children;
}
Map<Integer, Item> items = new HashMap<>();
function void build(int depth, int countChildren) {
...
}
function Item createItem() {
Item item = new Item();
item.id = Math.Random(0,10000);
return item;
}
Array看起来像这样
[
[
'id' => 1,
'children' => [
[
'id' => 10,
'children' => [
[
'id' => 100,
'children' => [
[
'id' => 1000,
],
[
'id' => 2000,
],
]
],
[
'id' => 200,
'children' => [
[
'id' => 1000,
],
[
'id' => 2000,
],
]
],
]
],
[
'id' => 20,
'children' => [
[
'id' => 100,
'children' => [
[
'id' => 1000,
],
[
'id' => 2000,
],
]
],
[
'id' => 200,
'children' => [
[
'id' => 1000,
],
[
'id' => 2000,
],
]
],
]
],
]
],
[
'id' => 1,
'children' => [
[
'id' => 10,
'children' => [
[
'id' => 100,
'children' => [
[
'id' => 1000,
],
[
'id' => 2000,
],
]
],
[
'id' => 200,
'children' => [
[
'id' => 1000,
],
[
'id' => 2000,
],
]
],
]
],
[
'id' => 20,
'children' => [
[
'id' => 100,
'children' => [
[
'id' => 1000,
],
[
'id' => 2000,
],
]
],
[
'id' => 200,
'children' => [
[
'id' => 1000,
],
[
'id' => 2000,
],
]
],
]
],
]
],
];