Advertisement
SwordPencil

graph.cpp

Dec 9th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.49 KB | None | 0 0
  1. #include "orgraph_search.h"
  2. //В этом файле описан класс "граф"
  3. istream& operator>>(istream& in, Graph& graph)
  4. {//Перегрузка оператора ввода для графа.
  5.     out << "Skolko v graphe budet vershin? VVOD: ";
  6.     in >> graph.numberOfVertecies;
  7.     SetMatrix(graph.adjacencyMatrix, graph.numberOfVertecies);
  8.     for(unsigned i = 0; i < graph.numberOfVertecies; i++)
  9.     {
  10.         for(unsigned j = 0; j < graph.numberOfVertecies; j++)
  11.         {
  12.             out << "\nSMEZHNOST' VERSHIN " << i << " -> " << j << "\n0 - NET 1 - DA. VVOD: ";
  13.             in >> graph.adjacencyMatrix[i][j];
  14.         }
  15.     }
  16.     return in;
  17. }
  18.  
  19. ostream& operator<<(ostream& out, Graph& graph)
  20. {//Перегрузка оператора вывода для графа.
  21.     if(graph.adjacencyMatrix != NULL)
  22.     {//Если наш граф не пустой, то мы его отображаем с помощью матрицы инцидентности
  23.         for(unsigned i = 0; i < graph.numberOfVertecies; i++)
  24.         {
  25.             for(unsigned j = 0; j < graph.numberOfVertecies; j++)
  26.                 out << graph.adjacencyMatrix[i][j] << " ";
  27.             out << "\n";
  28.         }
  29.     }
  30.     else
  31.         out << "(0 VERSHIN)";
  32.     return out;
  33. }
  34.  
  35. unsigned Graph::GetNumberOfVerticies()
  36. {
  37.     return numberOfVertecies;
  38. }
  39.  
  40. unsigned ** Graph::GetAdjacencyMatrix()
  41. {//Гет-метод для матрицы смежности.
  42.     return adjacencyMatrix;
  43. }
  44.  
  45. Graph::~Graph()
  46. {
  47.     for(unsigned i = 0; i < numberOfVertecies; i++)
  48.             delete [] adjacencyMatrix[i];
  49.     delete [] adjacencyMatrix;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement