Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2014
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. void findPath(imdb& db, string source, string target){
  2. list<path> paths;
  3. set<string> actors;
  4. set<film> films;
  5. path start(source);
  6. paths.push_back(start);
  7. while(!paths.empty() && paths.front().getLength()<=5){
  8. path connect=paths.front();
  9. paths.pop_front();
  10. vector<film>movies;
  11. db.getCredits(connect.getLastPlayer(),movies);
  12. for(int i=0; i < (int)movies.size(); i++){
  13. if(films.find(movies[i])==films.end()){
  14. films.insert(movies[i]);
  15. vector<string>cast;
  16. db.getCast(movies[i],cast);
  17. for(int j=0; j < (int)cast.size(); j++){
  18. if(actors.find(cast[j])==actors.end()){
  19. actors.insert(cast[j]);
  20. path clone=connect;
  21. connect.addConnection(movies[i], cast[j]);
  22. if(clone.getLastPlayer()==target){
  23. cout << clone << endl;
  24. return;
  25. }
  26. paths.push_back(clone);
  27. }
  28. }
  29. }
  30. }
  31. }
  32. cout << endl << "No path between those two people could be found." << endl << endl;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement