A long time ago practice, it is not very difficult to see.
Packageproject;classnode{Private intId//Private is only accessible to this class of objects and methods. PrivateString name; PublicNode Next;//point to next class node PublicNode (intId,string name)//a method for constructing a parameter{ This. id=ID; This. name=name; } Public voidDisplayLink ()//Display node content{System.out.println ("ID:" +id+ "" + "Name:" +name); }}classlinklist{PrivateNode first; Publiclinklist () { First=NULL; } Public BooleanIsEmpty ()//determine if the node is empty{if(first==NULL)return true; Else return false; } Public voidInsertintid,string name) {Node NewNode=NewNode (id,name); Newnode.next=first;//inserting a node with the head interpolation methodfirst=NewNode; } Public voidDisplaylist ()//traversing a linked list{Node current=NULL; Current=First ; while(current!=NULL) {current.displaylink (); Current=Current.next; }}} Public classtest11{ Public Static voidMain (string[] args) {linklist linklist=Newlinklist (); Linklist.insert (1, "Zhang San"); Linklist.insert (2, "John Doe"); Linklist.insert (3, "Harry"); Linklist.displaylist (); }}
Results:
Id:3 Name: Harry
Id:2 Name: John Doe
Id:1 Name: Zhang San
"Java linked list" Java header plug-in method to build a single linked list