class UniqueNumbers {

	public static TreeNode addNode(TreeNode root, int value) {
		if (root == null) {
			TreeNode node = new TreeNode();
			
			node.value = value;
			
			return node;
		}
		
		TreeNode current, previous;
		
		current = root;
		previous = null;
		
		while (current != null) {
			previous = current;
			
			if (current.value == value) {
				return root;
			}
			else if (current.value < value) {
				current = current.right;
			}
			else {
				current = current.left;
			}
		}
		
		if (previous.value < value) {
			previous.right = new TreeNode();
			previous.right.value = value;
		}
		else {
			previous.left = new TreeNode();
			previous.left.value = value;
		}
		
		return root;
	}

}