Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <iostream>
- using namespace std;
- /////////////// КЛАСС //////////////////////
- class MyGraph
- {
- private:
- short** matrix;
- unsigned short size;
- public:
- MyGraph(unsigned short count_of_tops, bool with_nul);
- ~MyGraph();
- public:
- void print_matrix();
- unsigned short count_of_ways();
- public:
- short* operator[](unsigned short index);
- public:
- unsigned short get_size();
- short** get_pointer();
- };
- /////////////// КОНСТРУКТОР ///////////////////////
- MyGraph::MyGraph(unsigned short count_of_tops, bool with_null = true)
- {
- size = count_of_tops;
- matrix = new short*[count_of_tops];
- for (unsigned short i = 0; i < count_of_tops; i++)
- matrix[i] = new short[count_of_tops];
- if (with_null)
- for (unsigned short i = 0; i < count_of_tops; i++)
- for (unsigned short j = 0; j < count_of_tops; j++)
- matrix[i][j] = 0;
- }
- /////////////// ДЕСТРУКТОР //////////////////////
- MyGraph::~MyGraph()
- {
- }
- /////////////// МЕТОДЫ //////////////////////
- void MyGraph::print_matrix()
- {
- for (unsigned short i = 0; i < size; i++)
- {
- for (unsigned short j = 0; j < size; j++)
- {
- cout << '\t' << matrix[i][j];
- }
- cout << endl;
- }
- }
- unsigned short MyGraph::count_of_ways()
- {
- unsigned short count = 0;
- for (unsigned short i = 0; i < size; i++)
- for (unsigned short j = 0; j < size; j++)
- if (matrix[i][j] != 0)
- count++;
- return count / 2;
- }
- /////////////// ГЕТТЕРЫ //////////////////////
- unsigned short MyGraph::get_size()
- {
- return size;
- }
- short** MyGraph::get_pointer()
- {
- return matrix;
- }
- /////////////// ОПЕРАТОРЫ //////////////////////
- short* MyGraph::operator[](unsigned short index)
- {
- return matrix[index];
- }
- //////////////////////////////////////////////////////////
- //////////////// ФУНКЦИИ //////////////////////////
- void console_read_matrix(MyGraph graph)
- {
- for (unsigned short i = 0; i < graph.get_size(); i++)
- for (unsigned short j = 0; j < graph.get_size(); j++)
- {
- cin >> graph[i][j];
- }
- }
- void console_write(MyGraph graph)
- {
- for (unsigned short i = 0; i < graph.get_size(); i++)
- {
- for (unsigned short j = 0; j < graph.get_size(); j++)
- {
- cout << graph[i][j] << ' ';
- }
- cout << endl;
- }
- cout << endl;
- }
- void console_read_ways(MyGraph graph, unsigned short count_of_ways, bool oriented = false)
- {
- unsigned short v1, v2;
- for (unsigned short i = 0; i < count_of_ways; i++)
- {
- // - 1
- cin >> v1 >> v2;
- graph[v1 - 1][v2 - 1] = 1;
- if (!oriented)
- graph[v2 - 1][v1 - 1] = 1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement