首先,定义一个Node类
class Node{
Object item;//store data
Node next;
public Node(Object item, Node next) {
this.item = item;
this.next = next;
}
之后将链表存放进数组:
public static void main(String[] args) {
//create a Node array
Node[] node = new Node[16];
//set a cat at index 2
Node cat = new Node("cat",null);
node[2] = cat;
//connect dog to the "next" of cat
Node dog = new Node("dog", null);
cat.next = dog;
}