//Function for finding a movie in the tree public MovieTreeNode Find(Movie movie) { string movieTitle = movie.getTitle(); MovieTreeNode currentNode = this; //While there is still a node to search in while (currentNode != null) { //If the movie it's searching for is the current node, return the node if (string.Compare(movieTitle, currentNode.movie.getTitle()) == 0 && isDeleted == false) { return(currentNode); } //If the movie is less than the current node and the left subtree is not empty, search the left subtree else if (string.Compare(movieTitle, currentNode.movie.getTitle()) < 0 && leftNode != null) { return(leftNode.FindRecursive(movie)); } //Otherwise search the right subtree if it's not empty else if (rightNode != null) { return(rightNode.FindRecursive(movie)); } //The movie doesn't exist in the tree else { return(null); } } return(null); }
//Function for finding node in tree public MovieTreeNode FindRecursive(Movie movie) { if (root != null) { return(root.FindRecursive(movie)); } else { return(null); } }