怎样用JAVA设计一个不带头结点的单链表类?
来源:百度知道 编辑:UC知道 时间:2024/05/26 08:02:58
一定要不带头结点!!!
循环链表?package com.liang.test.project;
public class ListTest{
private ListItem start=null;
private ListItem end=null;
private ListItem current=null;
private class ListItem{
private ListItem next;
int item;
public ListItem(int item){
this.item=item;
next=null;
}
public String toString(){
return item+"";
}
}
public ListTest(){}
public ListTest(int item){
if(start==null)
start=end=current=new ListItem(item);
}
public void addPoint(int item){
ListItem newEnd=new ListItem(item);
if(start==null){
start=end=newEnd;
}else{
end.next=newEnd;
end=newEnd;
}
}
public void deletePoint(int item){
current=start;
while(current.item!=item){
if(current.item==end.item){
System.out.print("你所要求删除的值不存在于此链表中");
System.exi