Example #1
0
        //Function for inserting a movie object into the tree
        public void Insert(Movie movieAdd)
        {
            string movieTitileAdd = movieAdd.getTitle();

            //If the movie to be added is greatter than the current node
            if (string.Compare(movieTitleAdd, movie.getTitle()) >= 0)
            {
                if (rightNode == null)
                {
                    //Movie is added to the right of the parent node if the right subtree is empty
                    rightNode = new MovieTreeNode(movieAdd);
                }
                else
                {
                    //If the right subtree isn't empty, go to the right subtree
                    rightNode.Insert(movieAdd);
                }
            }
            //If the movie to be added is less than the current node
            else
            {
                //If the left subtree is empty, add the movie to the left subtree
                if (leftNode == null)
                {
                    leftNode = new MovieTreeNode(movieAdd);
                }
                //If it isn't empty, go to the left subtree
                else
                {
                    leftNode.Insert(movieAdd);
                }
            }
        }
 //Function for inserting node into tree
 public void Insert(Movie movieAdd)
 {
     if (root != null)
     {
         root.Insert(movieAdd);
     }
     else
     {
         //Movie is added as the root node
         root = new MovieTreeNode(movieAdd);
     }
 }