Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. #include "Graphe.hpp"
  2.  
  3. Graphe::Graphe(const string nom) : nombreSommets(0){
  4. ifstream fichier;
  5. int i = 0, max;
  6.  
  7. fichier.open(nom.c_str());
  8. if (!fichier.fail()) {
  9.  
  10. int nombre_de_successeurs = 0;
  11. fichier >> nombreSommets;
  12. v.resize(nombreSommets);
  13.  
  14. for (int i = 0; i < nombreSommets; ++i) {
  15. fichier >> nombre_de_successeurs;
  16. v[i].resize(nombre_de_successeurs);
  17. for (int j = 0; j < nombre_de_successeurs; ++j) {
  18. fichier >> v[i][j];
  19. }
  20. }
  21. fichier.close();
  22. }
  23. }
  24.  
  25. void Graphe::afficher(const string nomFichierDot) {
  26. // création fichier .dot
  27. string nom = nomFichierDot + ".dot";
  28. ofstream fichierDot(nom);
  29.  
  30. if (fichierDot) {
  31. fichierDot << "digraph G {" << endl;
  32. for (int i=0; i<v.size(); ++i) {
  33. fichierDot << "/t'" << v[i][0] << "'";
  34. for (int j=1; j<v[i].size(); ++i) {
  35. fichierDot << " -> '" << v[i][j] << "'";
  36. }
  37. fichierDot << ";" << end;
  38. }
  39. fichierDot << "}";
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement