Created
November 12, 2013 23:39
-
-
Save rshepherd/7440813 to your computer and use it in GitHub Desktop.
A node illustrating the basic property of a linked list.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Node { | |
private int value; | |
private Node next; | |
public Node(int value) { | |
this.value = value; | |
} | |
public Node getNext() { | |
return next; | |
} | |
public void setNext(Node next) { | |
this.next = next; | |
} | |
public int getValue() { | |
return this.value; | |
} | |
public static class TestNode { | |
public static void main(String[] args) { | |
Node head = new Node(1); | |
// head[1|*] -> null | |
Node node2 = new Node(2); | |
// node2[2|*] -> null | |
head.setNext(node2); | |
// head[1|*] -> node2[2|*] -> null | |
Node n = head.getNext(); | |
while(n != null) { | |
n = n.getNext(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment