-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDirector.cpp
57 lines (47 loc) · 1.64 KB
/
Director.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <list>
#include <map>
#include <iostream>
// Container for storing directors mapped to their movies. Uses STL multimap.
class Director
{
private:
std::multimap <std::string, Movie*> map;
public:
/*
Description: This function will get all the movie nodes from movieCollection and will set up multimap for director class.
Time Complexity:
-Best Case: O(n)
-Worst Case: O(n)
*/
void createIndex(MovieCollection* obj)
{
std::multimap<std::string, Movie*>::iterator itr;
for (auto &pr :obj->map)
{
// Returns movie pointer
Movie* ptr = &pr.second;
// Mapping movie object pointers against there directors
this->map.insert({(*ptr).director_name,ptr});
}
}
/*
Description: Search and print movies of the given director.
Time Complexity for searching:
-Best Case: O(logn)
-Worst Case: O(logn)
Time Complexity for printing:
-Best Case: O(n)
-Worst Case: O(n)
*/
void search(std::string directorName)
{
// Returns all the movies of given director in log(n) time
auto it = this->map.equal_range(directorName);
std::cout<<"Director Name : " << (it.first)->first<< '\n'<<"\t\tMOVIES\n ";
// Printing the movies
for (auto itr = it.first; itr != it.second; ++itr)
{
std::cout<< (*itr->second).movie_title << '\n';
}
}
};