So I have the following class and am trying to make a method where an array is converted to a node list. I tried a for loop but I can't get it through my mind trying to set the next for each value.
public class Node {
public Node(int value, Node link) {
data = value;
next = link;
}
public void setData(int n) {
data = n;
}
public void setNext(Node link) {
next = link;
}
public int getData() {
return data;
}
public Node getNext() {
return next;
}
private int data;
private Node next;
public Node arrayToList(int[] a) {
for (int i = 0; i < a.length-1; i++) {
Node n = new Node(a[i], //a[i+1] but it must be a Node, so how would you loop the next Node);
}
}
}