Sunday, March 7, 2021

code for searching binary search tree (BST)

 bool  search (node *tree, int number)

{

//always check for NULL when dealing with pointers

//this is also the base case

        if (tree==NULL)

        {

                return false;

        }

//

        elseif (number < tree->number)

        {

                return search (tree->left, number);

        }

        elseif (number > tree->number)

        {

                return search (tree->right, number);

        }

        elseif (number == tree->number)

        {

                true;

        }


}



video location: lecture 5.  1:20:00 ~ 1:30:00

source: harvard cs50, david malan


]

No comments:

Post a Comment