This project implements a specialized dictionary for managing user-specific data on watched films. The primary data structure utilized is a trie, comprising binary trees, to efficiently organize user IDs. Each user ID in the trie points to a Binary Search Tree (BST), which stores the watched movies associated with that user. The project is structured in two phases: the Trie manages user IDs, and the BSTs associated with each Trie node store the watched movies for individual users.
The project follows a specialized two-phase structure:
- Trie Phase: Manages and organizes user IDs efficiently.
- BST Phase: Organizes and retrieves watched movies for individual users.
Represents a node in the trie with an array of children, a character (keyChar), a flag for the end of a key (isEndOfKey), and a pointer to associated data (data). Supports up to 128 children to accommodate alphanumeric characters.
Trie()
: Initializes a new trie with a root node.~Trie()
: Destructor for proper memory cleanup.void findStartingWith(std::string prefix, std::vector<T*> &results)
: Efficient search for keys starting with a specified prefix.void wildcardSearch(const std::string &wildcardKey, std::vector<T*> &results)
: Search for keys matching a wildcard pattern.T* search(std::string username)
: Searches for a specific key (username) in the trie.Trie &insert(const string &username)
: Inserts a new key (username) into the trie.void remove(std::string username)
: Removes a specific key (username) from the trie.void print(const std::string &primaryKey)
: Prints the entire trie or specific keys.void deleteTrieNode(TrieNode* node)
: Recursive function for proper memory cleanup.
Represents a node in the Binary Search Tree (BST) with a key, associated data, and pointers to left and right child nodes.
BST()
: Default constructor.~BST()
: Destructor for resource cleanup.TreeNode* getRoot()
: Returns a pointer to the root node.bool isEmpty()
: Checks if the tree is empty.BST& insert(const std::string key, const T& value)
: Inserts a new node with key and value.bool search(std::string key) const
: Searches for a node with a specified key.void remove(std::string key)
: Removes a node with a specified key.BST<T>* merge(BST<T>* bst)
: Merges nodes from two BSTs into a new BST.BST<T>* intersection(BST<T>* bst)
: Creates a new BST representing the intersection of two BSTs.std::vector<TreeNode> tree2vector(TreeNode* root)
: Converts BST nodes into a vector.void print()
: Displays the tree nodes hierarchically.
Represents a movie with attributes such as movie name, year, and rating.
Movie()
: Default constructor, initializes with default values.Movie(std::string movieName, int year, float rating)
: Constructor with provided values.Movie(const Movie& movie)
: Copy constructor for creating a new Movie object from an existing one.std::string getMovieName() const
: Getter for movie name.int getYear() const
: Getter for movie year.float getRating() const
: Getter for movie rating.bool operator==(const Movie &obj)
: Equality comparison for movies.
Represents a user with a username and a Binary Search Tree (BST) to store watched movies.
User()
: Default constructor, initializes with an empty username and an empty BST for movies.User(std::string username)
: Constructor with a provided username, initializes with an empty BST for movies.std::string getUsername()
: Getter for the username.BST<Movie>* getMovies()
: Getter for the BST storing watched movies.void addMovie(std::string movieName, Movie movie)
: Adds a movie to the user's collection.void removeMovie(Movie movie)
: Removes a movie from the user's collection.void searchMovie(Movie movie)
: Searches for a movie in the user's collection.void printMovies()
: Prints the movies in the user's collection.BST<Movie>* merge(BST<Movie> bst)
: Merges movies with another BST into a new BST.BST<Movie>* intersection(BST<Movie> bst)
: Calculates the intersection of movies with another BST.
Manages user interactions and provides methods to add/remove users, add/remove watched movies, find users, and more.
void addUser(std::string username)
: Inserts a new user with the given username into the trie data structure.
`UserInterface ui; ui.addUser("alice_smith");`
void removeUser(std::string username)
: Removes a user with a given username from the collection.
`ui.removeUser("bob_jones");`
void addWatchedMovie(std::string username, Movie movie)
: Adds a watched movie to a user identified by the given username.
`ui.addWatchedMovie("alice_smith", watchedMovie);`
void removeWatchedMovie(std::string username, Movie movie)
: Removes a specified movie from a user's watched list.
ui.removeWatchedMovie("alice_smith", movieToRemove);
User* findUser(std::string username)
: Locates and returns a User object based on a specified username.
User* requestedUser = ui.findUsersStartingWith("al");`
BST<Movie>* getWatchedMovies(std::string username)
: Returns a BST containing the movies watched by a user.
BST<Movie>* watchedMovies = ui.getWatchedMovies("alice_smith");
BST<Movie>* mergeWatchedMovies(std::string username1, std::string username2)
: Merges movies of two users into a new BST.
BST<Movie>* mergedMovies = ui.mergeWatchedMovies("alice_smith", "bob_jones");
BST<Movie>* intersectionWatchedMovies(std::string username1, std::string username2)
: Calculates the intersection of watched movies between two users.
BST<Movie>* intersectionMovies = ui.intersectionWatchedMovies("alice_smith", "bob_jones");
std::vector<User> findUsersStartingWith(std::string prefix)
: Searches for users with usernames starting with a specified prefix.std::vector<User> findUsersContains(std::string infix)
: Locates users with usernames containing a specified infix.std::vector<User> findUsersEndingWith(std::string suffix)
: Locates users with usernames ending in a specified suffix.
// Prefix Search
std::vector<User> foundUsersPrefix = ui.findUsersStartingWith("al");
// Infix Search
std::vector<User> foundUsersInfix = ui.findUsersContains("ice")
// Suffix Search
std::vector<User> foundUsersSuffix = ui.findUsersEndingWith("smith")
void printUsers()
: Prints details of all users managed by the collection.
ui.printUsers()
void printWatchedMovies(std::string username)
: Displays the watched movies of a specific user identified by their username.
ui.printWatchedMovies("alice_smith")