Last active
February 17, 2018 20:48
-
-
Save growlnx/339f5800f402832f52fe51110964a79f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "iostream" | |
| #include "vector" | |
| using namespace std; | |
| class Grafo{ | |
| private: | |
| // matrix de adjacencia | |
| vector<vector<int>>matrixAdj; | |
| public: | |
| // constroi uma matrix quadrada nula | |
| Grafo(unsigned quantVertice); | |
| // adiciona uma aresta ao grafo | |
| void set(unsigned x,unsigned y,int valor); | |
| // pega o valor de uma aresta | |
| int get(unsigned x,unsigned y); | |
| }; | |
| Grafo::Grafo(unsigned quantVertice){ | |
| for(unsigned cont=0;cont<quantVertice;cont++) | |
| this->matrixAdj.push_back(vector<int>(quantVertice,0)); | |
| } | |
| void Grafo::set(unsigned x,unsigned y,int valor){ | |
| this->matrixAdj[x][y]=valor; | |
| } | |
| int Grafo::get(unsigned x,unsigned y){ | |
| return this->matrixAdj[x][y]; | |
| } | |
| int main(){ | |
| // criando o grafo | |
| Grafo grafo(4); | |
| // adicionando arestas | |
| grafo.set(0,1,10); | |
| grafo.set(1,2,20); | |
| grafo.set(2,3,30); | |
| // pegando valores das arestas | |
| cout<<grafo.get(0,1)<<endl; | |
| cout<<grafo.get(1,2)<<endl; | |
| cout<<grafo.get(2,3)<<endl; | |
| return 0; | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment