-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
62 lines (50 loc) · 1.76 KB
/
main.cpp
File metadata and controls
62 lines (50 loc) · 1.76 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
#include <iostream>
#include <stdlib.h>
#include <vector>
#include "graph_list.hpp"
#include "graph_matrix.hpp"
#define N_NODI 4
using namespace std;
/*Not all the codes are mine, part are from :
-https://www.quora.com/What-is-the-most-simple-efficient-C++-code-for-Dijkstras-shortest-path-algorithm
-https://gist.github.com/arrayed/4121223743f60e2105cde3b83f26590a */
int main(){
/* test Vertex Matrix */
/*-----------------------------------------------------------*/
string s = "v1";
Vertex_Matrix v1(s,10);
Vertex_Matrix v2("v2",10);
Vertex_Matrix v3("v3",10);
cout << v1 << endl<< v2 <<endl << v3<< endl;
Graph_Matrix* grp = new Graph_Matrix(3);
grp->addVertex_Matrix(&v1);
grp->addVertex_Matrix(&v2);
grp->addVertex_Matrix(&v3);
grp->addEdge(&v1,&v2,2);
grp->addEdge(&v2,&v1,2);
grp->addEdge(&v2,&v3);
grp->DFS(&v1,&sum);
cout << *grp << endl;
grp->printMatrix();
grp->unMarkAll();
grp->BFS(&v1,&sum);
cout << *grp << endl;
cout << "------------------------------------------------------------" << endl;
/*------------------------------------------------------------*/
/*test graph list*/
graph_list* graph = new graph_list();
vector<Vertex*> nodi;
for(int i = 0; i < N_NODI; i++){
string s = "node "+to_string(i);
nodi.push_back(new Vertex( s,i));
graph->addVertex(nodi[i]);
}
graph->addEdges(nodi[0],nodi[1],2);
graph->addEdges(nodi[0],nodi[2],3);
graph->addEdges(nodi[1],nodi[3],10);
graph->addEdges(nodi[2],nodi[3],4);
graph->DFS(nodi[0]);
vector<int> dist = dijkstra(graph,nodi[0]);
for(int i : dist) cout << i << endl;
return 0;
}