Question
C++ Binary Search Tree Coding: #ifndef MOVIETREE_HPP #define MOVIETREE_HPP #include struct LLMovieNode { int ranking; std::string title; int year; float rating; struct LLMovieNode* next; LLMovieNode(){}
C++ Binary Search Tree Coding:
#ifndef MOVIETREE_HPP #define MOVIETREE_HPP
#include
struct LLMovieNode { int ranking; std::string title; int year; float rating; struct LLMovieNode* next;
LLMovieNode(){} LLMovieNode(int r, std::string t, int y, float q) : ranking(r), title(t), year(y), rating(q), next(NULL) {} };
struct TreeNode { LLMovieNode* head = NULL; char titleChar; TreeNode *parent = NULL; TreeNode *leftChild = NULL; TreeNode *rightChild = NULL; };
class MovieTree { public: MovieTree(); ~MovieTree(); void printMovieInventory(); void addMovie(int ranking, std::string title, int year, float rating); void deleteMovie(std::string title);
private: TreeNode *root; };
Your task is to implement a binary search tree of linked lists of movies:
MovieTree() Constructor: Initialize any member variables of the class to default
~MovieTree() Destructor: Free all memory that was allocated
void printMovieInventory() Print every movie in the data structure in alphabetical order of titles using the following format.
For TreeNode t and LLMovieNode m:
// for every TreeNode (t) in the tree
cout titleChar
// for every LLMovieNode (m) attached to t
cout > " title rating
void addMovie(int ranking, std::string title, int year, float rating) Add a movie to the data structure in the correct place based on its title.
If there is no tree node corresponding to the first letter of title, create it and insert it in the tree in the alphabetically correct position
Create a linked list node with ranking, title, year and rating, and insert it in the linked list associated with the tree node associated with the first letter of title. The linked list must also be in alphabetical order, such that for each node, node->title next->title
void deleteMovie(std::string title)
Delete the linked list node that contains title. If as a result of this deletion, the linked list becomes empty, delete the associated tree node.
If the movie does not exist in the data structure, print the following message cout
Your main function should first read information about each movie from a file and store that information in a MovieTree object. The name of the file with this information should be passed in as a command-line argument.
It is in the format:
cout
cout
cout
cout
Print the inventory: Call your trees printMovieInventory function
Delete a movie: Call your deleteMovie function on a title specified by the user. Prompt the user for a movie title using the following code: cout
Quit: Exit after printing a friendly message to the user: cout
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started