Upload New File

main
Joan PIERRON 3 years ago
parent a57357d186
commit cf64272348

@ -0,0 +1,54 @@
#include "Personne3.hpp"
#include "Contact3.hpp"
#include <iostream>
#include <unordered_set>
#include <queue>
using namespace std;
using namespace reseau2;
// #define TECHNIQUE_A
Personne::Personne(const std::string& prenom):prenom{prenom}{
// #ifdef TECHNIQUE_A
contacts = new ListeContact{};
// #else
// contacts = new Conteneur{};
// #endif
}
const string& Personne::getPrenom() const{
return this->prenom;
}
void reseau2::Personne::ajtContact(const Personne &personne) {
this->contacts->ajtContact(personne);
}
Personne::~Personne() {
delete contacts;
}
bool Personne::peutCommuniquerA(const Personne &p) const {
unordered_set<const Personne*> visited;
queue<const Personne*> pile;
pile.push(this);
while (!pile.empty()) {
const Personne* front = pile.front();
pile.pop();
for (const Personne* perso : front->contacts->getValue()) {
if (perso == &p) {
cout << this->prenom << " peut communiquer avec " << p.getPrenom() << "\n";
return true;
}
else if (visited.find(perso) == visited.end()) {
pile.push(perso);
visited.insert(perso);
}
}
}
cout << this->prenom << " ne peut pas communiquer avec " << p.getPrenom() << "\n";
return false;
}
Loading…
Cancel
Save