Advertisement
Guest User

idea

a guest
Nov 20th, 2019
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.42 KB | None | 0 0
  1. ActorGraph
  2. - movieMap: unordered_map<String, Movie*>
  3. - actorMap: unordered_map<String, Actor*>
  4. - actors: vector<Actor*>
  5.  
  6. Actor
  7. - name
  8. - movies: vector<Movie*>
  9.  
  10. Movie
  11. - name
  12. - year
  13. - actors: vector<Actor*>
  14.  
  15. # note — format of data is:
  16. actor, movie name, movie year
  17.  
  18. loadFromFile()::
  19. for each (actorName, movieName, year) {
  20.   Actor* a, Movie* m;
  21.  
  22.   if (!actorMap.has(actorName)) {
  23.     a = new Actor(actorName)
  24.   }
  25.  
  26.   if (!movieMap.has(movieName)) {
  27.     m = new Movie(movieName, year)
  28.   }
  29.  
  30.   a->movies.push_back(m)
  31.   m->actors.push_back(a)
  32. }
  33.  
  34. pathfinder(actorStart: String, actorEnd: String) {
  35.   q = queue<pair<String, Actor*>> // the String represents the string path and the Actor* represents the final actor in the path
  36.  
  37.   q.enqueue(actorMap.get(actorStart)->name, actorMap.get(actorStart))
  38.   q.top().second->checked = true
  39.  
  40.   while(!q.isEmpty()) {
  41.     stringPath, a = q.pop()
  42.  
  43.     if (a->name == actorEnd) {
  44.       return a
  45.     }
  46.  
  47.     for (let movieIndex = 0; movieIndex < a-> movies.size()); movieIndex++) {
  48.       let m = a->movies[movieIndex]
  49.       if (!m.checked) {
  50.         for (let actorIndex = 0; actorIndex < m->actors.size(); actorIndex++) {
  51.           let newActor = m->actors[actorIndex]
  52.           if (!newActor->checked) {
  53.             q.enqueue(stringPath + m->name + newActor->name, newActor)
  54.             newActor->checked = true
  55.           }
  56.         }
  57.       }
  58.     }
  59.   }
  60.   return -1;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement