Created
February 17, 2018 21:10
-
-
Save growlnx/8657e60bcf14364b857f14810f6ee675 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: | |
| // lista de aresta | |
| struct aresta{ | |
| unsigned x, y; | |
| int valor; | |
| }; | |
| vector<aresta> arestas; | |
| public: | |
| // 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); | |
| }; | |
| void Grafo::set(unsigned x, unsigned y, int valor){ | |
| this->arestas.push_back({x, y, valor}); | |
| } | |
| int Grafo::get(unsigned x, unsigned y){ | |
| for(unsigned cont=0;cont<this->arestas.size();cont++){ | |
| if(this->arestas[cont].x == x && this->arestas[cont].y == y) | |
| return this->arestas[cont].valor; | |
| } | |
| } | |
| int main(){ | |
| // criando o grafo | |
| Grafo grafo; | |
| // 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