forked from Ameesha15/DSA-ALGORITHMS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNode.java
More file actions
49 lines (43 loc) · 1.05 KB
/
Copy pathNode.java
File metadata and controls
49 lines (43 loc) · 1.05 KB
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
public class Node {
int data;
Node next;
public Node(int data){
this.data = data;
}
public Node append(Node node){
Node currentNode = this;
while(currentNode.next()!=null){
currentNode = currentNode.next();
}
currentNode.next = node;
return this;
}
public Node next(){
return this.next;
}
public int getData(){
return this.data;
}
//当前节点是否为最后一个节点;
public boolean isLast(){
return next==null;
}
//插入一个节点作为当前节点的下一个节点
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 void show(){
Node currentNode = this;
while(currentNode!=null){
System.out.println(currentNode.data);
currentNode=currentNode.next;
}
}
}