https://www.jianshu.com/u/0c7569d9705d
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
public class Node {
int data; Node next;
public Node(int data){ this.data = data; }
public Node append(Node node){ Node currentNode = this; while(true){ Node nextNode = currentNode.next; if(nextNode==null){ break; } currentNode = nextNode; } currentNode.next = node; return this; }
public void after(Node node){ Node nextNext = next; this.next=node; node.next=nextNext; }
public void removeNext(){ Node newNext = next.next; this.next=newNext; }
public Node next(){ return this.next; }
public int getData(){ return this.data; }
public void show(){ Node currentNode = this; while(true){ System.out.println(currentNode.data+""); currentNode = currentNode.next; if(currentNode==null){ break; } } } }
|
##单项循环链表
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| public class LoopNode {
int data; LoopNode next=this;
public LoopNode(int data){ this.data = data; }
public void after(LoopNode node){ LoopNode nextNext = next; this.next=node; node.next=nextNext; }
public void removeNext(){ LoopNode newNext = next.next; this.next=newNext; }
public LoopNode next(){ return this.next; }
public int getData(){ return this.data; } }
|