-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNode.java
More file actions
35 lines (26 loc) · 725 Bytes
/
Node.java
File metadata and controls
35 lines (26 loc) · 725 Bytes
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
public class Node {
public String data;
private Node next;
public Node(String data) {
this.data = data;
this.next = null;
}
public void setNextNode(Node node) {
this.next = node;
}
public Node getNextNode() {
return this.next;
}
public static void main(String[] args) {
Node strawberry = new Node("Berry Tasty");
Node banana = new Node("Banana-rama");
Node coconut = new Node("Nuts for Coconut");
strawberry.setNextNode(banana);
banana.setNextNode(coconut);
Node currentNode = strawberry;
while(currentNode != null){
System.out.println(currentNode.data);
currentNode = currentNode.getNextNode();
}
}
}