Starting from:

$29

Homework 5 Binary Search Tree

## Online Movie Service – Part 2

### Objectives
* Delete a node in a tree
* Delete a tree
* Traverse a BST

### Background

#### Online Movie Service (From Assignment 4)

You must have everything from Assignment 4 working to complete this assignment.
Make a copy of your Assignment 4 code to use as a starting base for this assignment.

### Functionality for Assignment 5

1\. **Delete a movie.**

When the user selects this option, they should be prompted for the title of the
movie to delete. Your code should then search the tree for that movie, delete
it if it’s found, re-assign to the parent and child pointers to bypass the deleted
node, and free the memory assigned to the node. If the movie is not found in
the search process, print “Movie not found” and do not attempt to delete.
A movie node should also be deleted when the quantity goes to 0 for any
movie.

*Be sure to test your program for movie nodes with 0 children, 1 child, or 2
children!*

2\. **Count movies in the tree.**

When the user selects this option, your program should traverse the tree in
any order and count the total movie nodes in the tree and print the count.

3\. **Delete the tree in the destructor using a postorder traversal.**

When the user selects quit, the destructor for the MovieTree class should be
called and in the destructor, all of the nodes in the tree should be deleted.
You need to use a postorder tree traversal for the delete or you will get
segmentation fault errors.

Incorporate this functionality into the menu you display.

### Implementation details

Your BST should be implemented in a class. You are provided with a MovieTree.hpp
file on the website that includes the class prototype for this assignment. You need to
implement the class functionality in a corresponding MovieTree.cpp file and
DriverHW5.cpp file.

More products