Node类:
package arraystolist;
/**
* 节点类
* @author hanxiaofan
*
*/
public class Node {
private final int value; //数据一旦放入就不可更改
private Node next;
public Node(int value) {
this.value = value;
this.next = null;
}
public Node getNext() {
return next;
}
public void setNext(Node next) {
this.next = next;
}
public int getValue() {
return value;
}
public static void printLiskedList(Node node) {
while(node != null) {
System.out.print(node.getValue());
System.out.print(" ");
node = node.getNext();
}
System.out.println("");
}
}
package arraystolist;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
*
* @author hanxiaofan
*
*/
public class LinkedListCreator {
/**
* 使用递归创建单向链表。最后一个元素指向null
* @param data
* @return
*/
public Node createLinkedList(List<Integ