package org.huchao.baseStructs;
/**
* 成人版java数据结构之链表删除
* @author huchao
* @since 2007.11.
*/
public class DelNode {
private Object item;
private DelNode next;
public DelNode(){
}
public DelNode(Object item){
this.item = item;
this.next = null;
}
public DelNode(Object item,DelNode next){
this.item = item;
this.next = next;
}
public static boolean isLast(DelNode instanse){
boolean suc = false;
if(null == instanse.getNext()){
System.out.println(instanse.getItem() + "是最后一个!");
suc = true;
}
return suc;
}
public static void itratorThem(DelNode instanse){
for(DelNode curr = instanse;!isLast(curr);curr = curr.getNext()){
System.out.println(curr.getItem() + "的P眼被" + curr.getNext().getItem() + "的JJ插入");
}
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
DelNode nodeA = new DelNode(new String("班长"));
DelNode nodeB = new DelNode(new String("排长"),nodeA);
DelNode nodeC = new DelNode(new String("连长"),nodeB);
System.out.println("当兵的过河,河里有吃球鱼,该怎么过呢?");
itratorThem(nodeC);
System.out.println("走着走着......");
System.out.println("吃球鱼没来,来了个大鳄鱼,大鳄鱼把排长给吞了!");
nodeC.setNext(nodeA);
nodeB.setNext(null);
nodeB = null;
itratorThem(nodeC);
}
public Object getItem() {
return item;
}
public void setItem(Object item) {
this.item = item;
}
public DelNode getNext() {
return next;
}
public void setNext(DelNode next) {
this.next = next;
}
}