Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <iostream>
- class MatrixGraph{
- private:
- std::vector<std::vector<bool>> data;
- public:
- MatrixGraph(size_t N);
- virtual ~MatrixGraph() {};
- virtual void AddEdge(size_t from, size_t to) = 0;
- virtual bool HasEdge(size_t from, size_t to) const = 0;
- virtual std::vector<size_t> GetVertices(size_t vertice) = 0;
- virtual size_t GetVerticesCount() = 0;
- };
- MatrixGraph::MatrixGraph(size_t N) {
- std::vector<bool> tmp;
- for (size_t i = 0; i < N; i++) {
- std::vector<bool> tmp;
- for (size_t j = 0; j < N; j++)
- tmp.push_back(false);
- data.push_back(tmp);
- }
- }
- void MatrixGraph::AddEdge(size_t from, size_t to) {
- data.at(from).at(to) = true;
- data.at(to).at(from) = true;
- }
- bool MatrixGraph::HasEdge(size_t from, size_t to) const {
- return data[from][to];
- }
- std::vector<size_t> MatrixGraph::GetVertices(size_t from) {
- std::vector<size_t> res;
- for (size_t to = 0; to < data[0].size(); to++) {
- if (data.at(from).at(to) == true)
- res.push_back(to);
- }
- return res;
- }
- size_t MatrixGraph::GetVerticesCount() {
- return data[0].size();
- }
- int main()
- {
- std::cout << "OK";
- std::cin.get();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement