-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgraph_methods.cpp
More file actions
65 lines (58 loc) · 1.3 KB
/
graph_methods.cpp
File metadata and controls
65 lines (58 loc) · 1.3 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
#include "BD_graph.h"
graph::graph()
{
this->V = 0;
this->E = 0;
}
void graph::clr()
{
this->V = 0;
this->E = 0;
edgeList.clear();
myvec.clear();
adjMatrix.clear();
}
void graph::addEdge(long src, long dest, float weight)
{
Edge newEdge;
newEdge.src = src;
newEdge.dest = dest;
newEdge.weight = weight;
edgeList.push_back(newEdge);
adjList tempset;
unordered_map<long, adjList>::iterator got = myvec.find(src);
if (got == myvec.end())
{
tempset.insert(make_pair(dest, weight));
E++;
myvec.insert(make_pair(src, tempset));
V++;
}
else
{
set<destWeight>::const_iterator its = got->second.find(make_pair(dest, weight));
if (its == got->second.end())
{
got->second.insert(make_pair(dest, weight));
E++;
}
}
tempset.clear();
got = myvec.find(dest);
if (got == myvec.end())
{
tempset.insert(make_pair(src, weight));
//E++;
myvec.insert(make_pair(dest, tempset));
V++;
}
else
{
set<destWeight>::const_iterator its = got->second.find(make_pair(src, weight));
if (its == got->second.end())
{
got->second.insert(make_pair(src, weight));
//E++;
}
}
}