Java版資料結構之迴圈連結串列的實現
阿新 • • 發佈:2018-12-17
簡介
- 在指定結點後新增一個結點
- 刪除指定結點的下一個結點
- 獲取下一個結點
- 獲取結點資料
public class LoopNode { int data;//資料域 LoopNode next;//下一個結點 public LoopNode(int data) { this.data = data; next=this; } //在指定結點後新增一個結點 public LoopNode add(LoopNode node){ node.next=this.next; this.next=node; return this; } //刪除指定結點的下一個結點 public LoopNode delete(){ this.next=this.next.next; return this; } //獲取下一個結點 public LoopNode getNext(){ return this.next; } //獲取結點資料 public int getData(){ return this.data; } }