Skip to content

Instantly share code, notes, and snippets.

@thomasballinger
Created March 9, 2014 19:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomasballinger/9453188 to your computer and use it in GitHub Desktop.
Save thomasballinger/9453188 to your computer and use it in GitHub Desktop.
public class Node {
public Node left;
public Node right;
public int value;
public Node(int value, Node left, Node right){
this.value = value;
this.left = left;
this.right = right;
}
public Node(int value){
this.value = value;
}
public void print_depth_first(){
System.out.printf("%d, ", this.value);
if (this.left != null){
this.left.print_depth_first();
}
if (this.right != null){
this.right.print_depth_first();
}
}
public static void main(String[] args) {
Node n = new Node(1,
new Node(2,
new Node(3),
new Node(4)),
new Node(5));
n.print_depth_first();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment