Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ActorGraph
- - movieMap: unordered_map<String, Movie*>
- - actorMap: unordered_map<String, Actor*>
- - actors: vector<Actor*>
- Actor
- - name
- - movies: vector<Movie*>
- Movie
- - name
- - year
- - actors: vector<Actor*>
- # note — format of data is:
- actor, movie name, movie year
- loadFromFile()::
- for each (actorName, movieName, year) {
- Actor* a, Movie* m;
- if (!actorMap.has(actorName)) {
- a = new Actor(actorName)
- }
- if (!movieMap.has(movieName)) {
- m = new Movie(movieName, year)
- }
- a->movies.push_back(m)
- m->actors.push_back(a)
- }
- pathfinder(actorStart: String, actorEnd: String) {
- q = queue<pair<String, Actor*>> // the String represents the string path and the Actor* represents the final actor in the path
- q.enqueue(actorMap.get(actorStart)->name, actorMap.get(actorStart))
- q.top().second->checked = true
- while(!q.isEmpty()) {
- stringPath, a = q.pop()
- if (a->name == actorEnd) {
- return a
- }
- for (let movieIndex = 0; movieIndex < a-> movies.size()); movieIndex++) {
- let m = a->movies[movieIndex]
- if (!m.checked) {
- for (let actorIndex = 0; actorIndex < m->actors.size(); actorIndex++) {
- let newActor = m->actors[actorIndex]
- if (!newActor->checked) {
- q.enqueue(stringPath + m->name + newActor->name, newActor)
- newActor->checked = true
- }
- }
- }
- }
- }
- return -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement