Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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