-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
67 lines (53 loc) · 1.96 KB
/
main.cpp
File metadata and controls
67 lines (53 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "./include/Grafo.hpp"
#include "./include/GrafoLista.hpp"
#include "./include/GrafoMatriz.hpp"
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char *argv[]) {
if (argc < 4) {
cout << "Uso: " << argv[0] << " -d -m|-l grafo.txt" << endl;
return 1;
}
string flagDirecao = argv[1];
string flagEstrutura = argv[2]; // -m ou -l
string nomeArquivo = argv[3];
Grafo *grafo = nullptr;
if (flagEstrutura == "-m")
grafo = new GrafoMatriz();
else if (flagEstrutura == "-l")
grafo = new GrafoLista();
else {
cout << "Estrutura inválida. Use -m para matriz ou -l para lista." << endl;
return 1;
}
grafo->carrega_grafo(nomeArquivo);
// cout << "Grafo carregado: Ordem = " << grafo->get_ordem() << endl;
// grafo->imprime_grafo();
// Exclusão de nó 1 (se existir)
cout << "Excluindo nó 1..." << endl;
grafo->deleta_no(1);
// Exclusão da primeira aresta do nó 2 (se existir)
cout << "Excluindo primeira aresta do nó 2..." << endl;
IntList vizinhos = grafo->get_vizinhos(2);
if (vizinhos.size() > 0) {
int primeiroVizinho = vizinhos.get(0);
grafo->deleta_aresta(2, primeiroVizinho);
}
// grafo->imprime_grafo();
// Impressão das propriedades do grafo
cout << "Grau: " << grafo->get_grau() << endl;
cout << "Ordem: " << grafo->get_ordem() << endl;
cout << "Direcionado: " << (grafo->eh_direcionado() ? "Sim" : "Nao") << endl;
cout << "Vertices ponderados: "
<< (grafo->vertice_ponderado() ? "Sim" : "Nao") << endl;
cout << "Arestas ponderadas: " << (grafo->aresta_ponderada() ? "Sim" : "Nao")
<< endl;
cout << "Completo: " << (grafo->eh_completo() ? "Sim" : "Nao") << endl;
// Cálculo e impressão da maior menor distância (diâmetro do grafo)
Grafo::ResultadoDistancia res = grafo->calculaMaiorMenorDistancia();
cout << "Maior menor distância: (" << res.no1 << "-" << res.no2 << ") "
<< res.distancia << endl;
delete grafo;
return 0;
}