[英]How to copy values from 2d array to doubly linked list
How can I values from 2d array to doubly linked list? 如何将2d数组中的值赋给双向链表? I know how to do it with ArrayList but I have no idea how to implement it with doubly linked lists. 我知道如何使用ArrayList来实现,但是我不知道如何使用双向链接列表来实现它。 How could I copy everything from 2d array to LinkedList? 如何将2d数组中的所有内容复制到LinkedList? Do I need LinkedList of LinkedLists? 我需要LinkedLists的LinkedList吗?
If I have 如果我有
int[][] myArray = {{1,2,3}
{4,5,6},
{7,8,9}};
Then the LinkedList should look like exactly the same, ie: 然后,LinkedList应该看起来完全一样,即:
[[1,2,3]
[4,5,6],
[7,8,9];
public void copyFromArray(int[][] myArray){
}
public class Node<Integer> {
public Integer data;
public Node<Integer> prev, next;
public Node( Integer d, Node<Integer> p, Node<Integer> n ){
this.data = d;
this.prev = new Node();
this.next = new Node();
}
}
yes, you need a LinkedList of LinkedLists: 是的,您需要一个LinkedLists的LinkedList:
LinkedList<LinkedList<Integer>> list = new LinkedList<>();
int[][] myArray = { {1, 2, 3}, {4,5,6},{7,8,9} };
for (int i = 0; myArray.length >= i; i++) {
LinkedList<Integer> auxList = new LinkedList<>();
for (int j = 0; myArray[i].length >= j; j++) {
auxList.add(myArray[i][j]);
}
list.add(auxList);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.