Java language to create linked list

class Link{
public long dDate;
public Link next; public Link(long dd){ dDate=dd; } // public Link() { // // } // public void displayLink(){ System.out.print(dDate+" "); }












}


class LinkList{
private Link first; public LinkList(){//The constructor initializes the header first=null; } public void insertFirst(long dd){//Insert header Link newLink =new Link(dd); newLink.next= first; first=newLink; } public Link find(int key){//Find node Link current=first; while(current.dDate!=key){ if(current.next==null){ return null;//No Find } else{ current=current.next; } } return current; } public Link remove(int key){//Remove node Link current =first; Link previous=first;//Record the parent node of the deleted node while(current. dDate!=key){//Find the node to delete if(current.next==null){





























return null;//没找到
}
else{
previous=current;
current=current.next;
}
}
if(current==first){//删除头结点
first=first.next;
}
else{//删除非头结点
previous.next=current.next;
}
return current;
}public void displayList(){//显示链表System.out.print("List(first-->last):");Link current =first;while(current!=null){current.displayLink();current=current.next;}System.out.println("");}}











Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325382997&siteId=291194637