Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

c loop through binary search tree

bool iterativeSearch(struct Node* root, int key)
{
    // Traverse until root reaches to dead end
    while (root != NULL) {
        // pass right subtree as new tree
        if (key > root->data)
            root = root->right;
 
        // pass left subtree as new tree
        else if (key < root->data)
            root = root->left;
        else
            return true; // if the key is found return 1
    }
    return false;
}
 
PREVIOUS NEXT
Tagged: #loop #binary #search #tree
ADD COMMENT
Topic
Name
1+7 =