Created
March 9, 2014 19:30
-
-
Save thomasballinger/9453188 to your computer and use it in GitHub Desktop.
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 { | |
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