lib/binary_search_tree/tree.rb
# Inserts a value to the Binary Search Tree (or sub-tree denoted by the `node` attribute).
# @param value [Numeric] the value to be inserted to the tree
# @param node [BinarySearchTree::Node] the tree/sub-tree root node
# @return [BinarySearchTree::Node] the BST Node that was inserted
Inserts a value to the Binary Search Tree (or sub-tree denoted by the `node` attribute).
Inserts a value to the Binary Search Tree ( or sub - tree denoted by the ` node ` attribute ) .
def insert(value, node = root)
      if node.nil?
        new_node = Node.new(value)
      elsif value < node.value
        new_node = insert(value, node.left)
        node.left = new_node unless node.left
      else
        new_node = insert(value, node.right)
        node.right = new_node unless node.right
      end
      @root = new_node unless root
      new_node
    end
def insert ( value , node = root ) if node . nil? new_node = Node . new ( value ) elsif value < node . value new_node = insert ( value , node . left ) node . left = new_node unless node . left else new_node = insert ( value , node . right ) node . right = new_node unless node . right end @root = new_node unless root new_node end
Inserts a value to the Binary Search Tree (or sub-tree denoted by the `node` attribute).
Inserts a value to the Binary Search Tree ( or sub - tree denoted by the ` node ` attribute ) .
the BST Node that was inserted
the BST Node that was inserted
BinarySearchTree::Node
value
the value to be inserted to the tree
the value to be inserted to the tree
node
the tree/sub-tree root node
the tree / sub - tree root node
root