‫So now we'll create our contains function and just like we had with our insert function, we're going
‫to start with a video where we walk through all of the steps.
‫That's what this video is.
‫And then in the next video we'll use those steps to write the code.
‫So with this function, we just want to see if a particular value is in our tree.
‫So if we're looking for the number 27, the tree does have a 27.
‫So we would return.
‫True.
‫But if we were looking for the number 17, the tree does not have a number 17, so it should return
‫false if we have an empty tree.
‫Obviously whatever value we're looking for is not in the tree.
‫So this becomes the first item on our list.
‫We'll say if root is equal to null pointer return false.
‫Now let's bring back our tree.
‫And just like we saw with our insert function, we need to have a variable that we can use to traverse
‫through the tree.
‫We'll call that temp.
‫And if we're looking for the number 27, we will compare 27 against 47 and go left and then 27 is greater
‫than 21 and that we would go right.
‫And then finally we see that this is the number we're looking for and we would return.
‫True.
‫So let's bring this back up to the top.
‫We'll add this to the list that we're going to create a variable temp that we set equal to root.
‫So now let's look at a situation where we're looking for a number that is not in the tree.
‫Let's say we're looking for the number 17.
‫It is less than so we'll go left.
‫It's less than 21.
‫We go left again and it's less than 18.
‫So we go left again.
‫So now temp is equal to null pointer.
‫And if this ever happens, we want to break out of our wild loop that we're using to traverse through
‫the tree.
‫So we'll say while temp is not equal to null pointer, so we'll keep iterating through this as long
‫as we don't have this condition happen as we are traversing through this tree inside of this wild loop,
‫we have a few possibilities.
‫Either the number we are looking for is less than the node we're comparing it to and will go left.
‫Or it's greater than.
‫And we'll go.
‫Right.
‫Or its equal and will return true.
‫And then there's a fourth possibility.
‫And that fourth possibility is we have this scenario where it is equal to null pointer, in which case
‫we return false.
‫So these are all of the steps for the contains function.
‫We'll pick up right here in the next video where we use these steps to code this.
‫But for now, that is our intro to contains.