-
Notifications
You must be signed in to change notification settings - Fork 0
/
Graph.cpp
45 lines (44 loc) · 1.15 KB
/
Graph.cpp
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
/*
* Graph.cpp
* Author: mohammad asadolahi
* https://github.com/mohammadAsadolahi
*/
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <utility> // pair
#include <time.h> // time
#include <stdlib.h> // srand, rand
#include <algorithm>
using namespace std;
class Graph
{
public:
int vertexCount; // number of Vertices
int EdgeCount; // number of total Edge
int startVertex; // start vertex
map<pair<int ,int >,int >edges; // map of the edges
// public:
Graph (int vertexCount ,int startVertex)
{
this->vertexCount = vertexCount;
this->startVertex = startVertex;
this->EdgeCount = 0;
}
void printGraph ( )
{
map<pair<int ,int >,int >::iterator it;
for (it = edges.begin( ) ;it != edges.end( ) ;++it)
{
cout << it->first.first << " linked to vertex "
<< it->first.second << " with weight "
<< it->second << endl;
}
}
void addEdge (int source ,int destination ,int weight) // add a edge
{
edges[make_pair(source ,destination)] = weight;// adds edge in the map
}
};