The data structure is learned, the Java implementation
PackageCom.gh.Link;/*** Implementation of the linked list *@authorGanhang **/ Public classLinks { Public Static voidMain (string[] args) {nodemanage nm=NewNodemanage (); Nm.add ("Node 1"); Nm.add ("Node 2"); Nm.add ("Node 3"); Nm.add ("Node 4"); Nm.add ("Node 5"); Nm.add ("Node 6"); Nm.add ("Node 7"); Nm.add ("Node 8"); Nm.add ("Node 9"); Nm.add ("Node 10"); Nm.print (); Nm.delete ("Node 3"); Nm.print (); }}
PackageCom.gh.Link;/*** List management (additions and deletions) *@authorGanhang **/ Public classNodemanage {PrivateNode Root; Public voidAdd (String name) {if(Root = =NULL) {root=NewNode (name); } Else{root.addnode (name); } } Public voidDelete (String name) {if(Root! =NULL) { if(root.name.equals (name)) {root=Root.next; } Else{root.delnode (name); } } } Public voidprint () {if(root!=NULL) {System.out.print (root.name); Root.printnode (); System.out.println (); } } classNode {//Inner class implements the operation of the node under the root node PrivateString name; PrivateNode Next; PublicNode (String name) { This. Name =name; } Public voidAddNode (String name) {if( This. Next = =NULL) { This. Next =NewNode (name); } Else { This. Next.addnode (name); } } Public voidDelnode (String name) {if( This. Next! =NULL) { if( This. Next.name.equals (name)) { This. Next = This. Next.next; } Else { This. Next.delnode (name); } } } Public voidPrintnode () {if( This. next!=NULL) {System.out.print ("-" + This. Next.name); This. Next.printnode (); } } }}
List of Java learning links