Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void findPath(imdb& db, string source, string target){
- list<path> paths;
- set<string> actors;
- set<film> films;
- path start(source);
- paths.push_back(start);
- while(!paths.empty() && paths.front().getLength()<=5){
- path connect=paths.front();
- paths.pop_front();
- vector<film>movies;
- db.getCredits(connect.getLastPlayer(),movies);
- for(int i=0; i < (int)movies.size(); i++){
- if(films.find(movies[i])==films.end()){
- films.insert(movies[i]);
- vector<string>cast;
- db.getCast(movies[i],cast);
- for(int j=0; j < (int)cast.size(); j++){
- if(actors.find(cast[j])==actors.end()){
- actors.insert(cast[j]);
- path clone=connect;
- connect.addConnection(movies[i], cast[j]);
- if(clone.getLastPlayer()==target){
- cout << clone << endl;
- return;
- }
- paths.push_back(clone);
- }
- }
- }
- }
- }
- cout << endl << "No path between those two people could be found." << endl << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement