Answers for "search for a node in a binary search tree"

0

search node in tree javascript

var stack = [], node, ii;
stack.push(root);

while (stack.length > 0) {
    node = stack.pop();
    if (node.title == 'randomNode_1') {
        // Found it!
        return node;
    } else if (node.children && node.children.length) {
        for (ii = 0; ii < node.children.length; ii += 1) {
            stack.push(node.children[ii]);
        }
    }
}

// Didn't find it. Return null.
return null;
Posted by: Guest on May-21-2020
0

Searching for a node in a BST

def search(bst, value):
    if bst is None or bst.get_data() == value:
        return bst

    if bst.get_data() < value:
        return search(bst.get_right(), value)

    return search(bst.get_left(), value)
Posted by: Guest on May-24-2021
0

insert binary search tree

void BSNode::insert(std::string value) {

	if (this->_data == value) {
		_count++;
		return;
	}

	if (this->_data > value) {
		if (this->getLeft() == nullptr) {
			this->_left = new BSNode(value);
		}
		this->getLeft()->insert(value);
		return;
	}

	if (this->getRight() == nullptr) {
		this->_right = new BSNode(value);
		return;
	}
	this->getRight()->insert(value);
}
Posted by: Guest on January-03-2021

Code answers related to "search for a node in a binary search tree"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language