Skip to content

Instantly share code, notes, and snippets.

@rshepherd
Created November 12, 2013 23:39
Show Gist options
  • Save rshepherd/7440813 to your computer and use it in GitHub Desktop.
Save rshepherd/7440813 to your computer and use it in GitHub Desktop.
A node illustrating the basic property of a linked list.
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