Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool generateShortestPath(string source,string target,imdb& db){
- list<path> partialPaths; // functions as a queue
- set<string> previouslySeenActors;
- set<film> previouslySeenFilms;
- path way(source);
- partialPaths.push_back(way);
- while(!partialPaths.empty() && (partiliaPaths.front()).pathLength <= 5){
- way = partiliaPaths.front();
- partiliaPaths.pop_front();
- vector<film> films;
- string name = way.getLastPlayer();
- db.getCredits(name,films);
- for(int i = 0; i < films.size(); i++){
- previouslySeenFilms.insert(films[i]);
- vector<string> actors;
- db.getCast(films[i],actors);
- for(int j = 0;j < actors.size();j ++){
- previouslySeenActors.insert(actors[i]);
- path clone = way;
- clone.addConnection(films[i],actors[j]);
- if(actors[j]==target){
- cout << clone << '\n';
- return true;
- }
- partialPaths.push_bach(clone);
- }
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement