弄个简单的。链表大概就这样 class LinkList{ private LinkNode first;//This field is used to reference to first link on list public LinkList(){//The coustructor of Linklist class first=null;//This Statement indicate that there is no items on list yet } public boolean isEmpty(){ return(first==null); } public void insertFirst(double dd){ LinkNode newLink=new LinkNode(dd); newLink.next=first; first=newLink; } public LinkNode deleteFirst(){ LinkNode temp=first; first=first.next; return temp; } public void displayList(){ LinkNode current=first; while(current!=null){ current.displayLinkNode(); current=current.next; } } } class LinkNode{ private double dDate;//The data of the LinkList; public LinkNode next; public LinkNode(double dd){ this.dDate=dd; } public void displayLinkNode(){ System.out.println("The Date of this NOde is:"+this.dDate); } } public class Test{ public static void main(String[] args){ LinkList theList=new LinkList(); theList.insertFirst(22.22); theList.insertFirst(33.33); theList.displayList(); System.out.println("is Empty or not:"+theList.isEmpty()); theList.deleteFirst(); System.out.println("After we delete the first Node:"); theList.displayList(); theList.insertFirst(44.44); System.out.println("After we insert the first Node:"); theList.displayList(); } }
class LinkList{
private LinkNode first;//This field is used to reference to first link on list
public LinkList(){//The coustructor of Linklist class
first=null;//This Statement indicate that there is no items on list yet
}
public boolean isEmpty(){
return(first==null);
}
public void insertFirst(double dd){
LinkNode newLink=new LinkNode(dd);
newLink.next=first;
first=newLink;
}
public LinkNode deleteFirst(){
LinkNode temp=first;
first=first.next;
return temp;
}
public void displayList(){
LinkNode current=first;
while(current!=null){
current.displayLinkNode();
current=current.next;
}
}
}
class LinkNode{
private double dDate;//The data of the LinkList;
public LinkNode next;
public LinkNode(double dd){
this.dDate=dd;
}
public void displayLinkNode(){
System.out.println("The Date of this NOde is:"+this.dDate);
}
}
public class Test{
public static void main(String[] args){
LinkList theList=new LinkList();
theList.insertFirst(22.22);
theList.insertFirst(33.33);
theList.displayList();
System.out.println("is Empty or not:"+theList.isEmpty());
theList.deleteFirst();
System.out.println("After we delete the first Node:");
theList.displayList();
theList.insertFirst(44.44);
System.out.println("After we insert the first Node:");
theList.displayList();
}
}