Used to C++,java write up really not very good ... No nonsense, on the code ...
Package Javainnerclassdemo;class link{class node{private string name;private node next;public node (string name) { This.name=name;} public void SetName (String name) {this. name = name;} Public String GetName () {return this.name;} public void AddNode (Node newnode) {if (this.next==null) This.next=newnode;elsethis.next.addnode (newnode);} public void Printnode () {if (this.next!=null) {System.out.print (this.name); System.out.print ("--");} ElseSystem.out.println (this.name); if (this.next!=null) This.next.printnode ();} public boolean Searchnode (String name) {if (this.name.equals (name)) {return true;} Else{if (this.next!=null) {return this.next.searchnode (name);} Else{return false;}}} public void Deletenode (Node prenode,string name) {if (this.name.equals (name)) {prenode.next = This.next;} Else{this.next.deletenode (This,name);}}} Private Node root;public void Add (String name) {Node NewNode = new Node (name); if (this.root==null) This.root=newnode; Elsethis.root.addnode (newnode);} public void print () {if (this.root!=null) { The reason for the external judgment, because printnode need to iterate This.root.printnode ();} ElseSystem.out.println ("The linked list is empty, cannot print!") ");} public boolean search (String name) {if (This.root.searchnode (name) ==true) return True;elsereturn false;} public void Delete (String name) {if (This.search (name)) {///Determine if this node exists if (This.root.name.equals (name)) {if ( This.root.next!=null) {this.root = This.root.next;//change root node}else{this.root = null;//Cancel}}else{if (This.root.next!=null) {This.root.next.deleteNode (root,name);}}} ELSESYSTEM.OUT.PRINTLN ("The node you want to delete does not exist!") ");}} public class Linklistdemo {public static void main (string[] args) {link L = new Link (); L.add ("Walkthehorizon"); L.add ("Already") , L.add ("No"), L.add ("able to block"), L.add ("the"), L.add ("" "); System.out.println ("Print List"); L.print (); System.out.println ("Find linked list"); System.out.println (L.search ("Walkthehorizon")); System.out.println (L.search ("The Blade of Exile"); System.out.println ("Delete node"); L.delete (""); L.print ();}}The core of Java's single-linked list implementation is the multi-level iteration.
Java single-Link list code implementation