[英]How to implement Rootish Array Stack Data Structure in Java, using jagged array or pointer array
Basically i just want to know that how can i get an array which contains another array and i could shrink it or grow it, For example A{a,b,c,d} a{0}, b{1,2} c{3,4,5} d{6,7,8,9} . 基本上,我只是想知道如何获取包含另一个数组的数组,并且可以缩小或增长它,例如A {a,b,c,d} a {0},b {1,2} c {3,4,5} d {6,7,8,9}。 And if i want to add another integer in it then i can grow it A{a,b,c,d,e} a{0}, b{1,2} c{3,4,5} d{6,7,8,9} e{10} in java.
如果我想在其中添加另一个整数,则可以将其增长为A {a,b,c,d,e} a {0},b {1,2} c {3,4,5} d {6, Java中的7,8,9} e {10}。
Rootish Array Stack is basically a data structure just like array which stores array in the way i mentioned above..... Rootish Array Stack基本上是一种数据结构,就像array一样,它以我上面提到的方式存储数组.....
I tried using jagged array but i cannot grow it or shrink it 我尝试使用锯齿状数组,但无法增大或缩小
This is simply a List of List
. 这只是
List of List
。 You can take help from below example code. 您可以从以下示例代码获取帮助。 The size of the
List
can increase or decrease as you add/remove elements. 添加或删除元素时,
List
的大小可以增加或减小。
List<List<Integer>> listOfLists = new ArrayList<List<Integer>>();
import java.util.ArrayList;
import java.util.List;
public class ListOfLists {
public static void main(String args[]) {
List<List<Integer>> listOfLists = new ArrayList<List<Integer>>();
List<Integer> aList = new ArrayList<Integer>();
List<Integer> bList = new ArrayList<Integer>();
List<Integer> cList = new ArrayList<Integer>();
List<Integer> dList = new ArrayList<Integer>();
aList.add(0);
bList.add(1); bList.add(2);
cList.add(3); cList.add(4); cList.add(5);
dList.add(6); dList.add(7); dList.add(8); dList.add(9);
listOfLists.add(aList);
listOfLists.add(bList);
listOfLists.add(cList);
listOfLists.add(dList);
for (List<Integer> list : listOfLists) {
for (Integer i : list) {
System.out.print(i + "\t");
}
System.out.println();
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.