Skip to content

Instantly share code, notes, and snippets.

@Jun711
Created February 15, 2018 23:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jun711/792dbe47c2e294312b5ee7a13ca1f49d to your computer and use it in GitHub Desktop.
Save Jun711/792dbe47c2e294312b5ee7a13ca1f49d to your computer and use it in GitHub Desktop.
TestDome - Binary Search Tree
class Node {
public int value;
public Node left, right;
public Node(int value, Node left, Node right) {
this.value = value;
this.left = left;
this.right = right;
}
}
public class BinarySearchTree {
public static boolean contains(Node root, int value) {
if (root == null)
return false;
if (root.value == value)
return true;
else if (root.value > value)
return contains(root.left, value);
else
return contains(root.right, value);
}
public static void main(String[] args) {
Node n1 = new Node(1, null, null);
Node n3 = new Node(3, null, null);
Node n2 = new Node(2, n1, n3);
System.out.println(contains(n2, 3));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment