package org.huchao.baseStructs;
/**
* 成人版java数据结构之单链表的建立和遍历
* @author huchao
* @since 2007.11.
*/
public class Node1 {
private Object item;
private Node1 next;
public Node1(Object newItem){
item = newItem;
next = null;
}
public Node1(Object newItem,Node1 nextNode){
item = newItem;
next = nextNode;
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Node1 head = new Node1(new String("上校"));
Node1 second = new Node1(new String("上尉"),head);
Node1 third = new Node1(new String("中尉"),second);
System.out.println("当兵的过河,河里有吃球鱼,该怎么过呢?");
for(Node1 curr = third;null != curr;curr = curr.getNext()){
if(isLast(curr)){
System.out.print(curr.getItem() + "走在最后面");
}else
System.out.println(curr.getItem() + "的P眼被" + curr.getNext().item + "的的JJ插入");
}
}
public static boolean isLast(Node1 node){
if(null == node.getNext())
return true;
return false;
}
public Object getItem() {
return item;
}
public void setItem(Object item) {
this.item = item;
}
public Node1 getNext() {
return next;
}
public void setNext(Node1 next) {
this.next = next;
}
}