-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEdge.cpp
More file actions
61 lines (51 loc) · 944 Bytes
/
Copy pathEdge.cpp
File metadata and controls
61 lines (51 loc) · 944 Bytes
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
#include "Edge.h"
Edge ::Edge()
{
this->src = nullptr;
this->dst = nullptr;
this->weight = INF;
}
Edge ::Edge(Vertex *s, Vertex *d, int w)
{
this->src = s;
this->dst = d;
this->weight = w;
}
void Edge::setSource(Vertex *s)
{
this->src = s;
}
void Edge::setDestination(Vertex *d)
{
this->dst = d;
}
void Edge::setWeight(int w)
{
this->weight = w;
}
Vertex *Edge ::getSource()
{
return this->src;
}
Vertex *Edge ::getDestination()
{
return this->dst;
}
int Edge ::getWeight()
{
return this->weight;
}
void Edge :: showEdge()
{
cout << "{(" << this->src->getIndex() << ", " << this->dst->getIndex() << "), " << this->weight << "}" << endl;
}
void Edge ::relax()
{
Vertex *u = this->src;
Vertex *v = this->dst;
if (v->getDistance() > u->getDistance() + this->weight)
{
v->setDistance(u->getDistance() + this->weight);
v->setPredecessor(u);
}
}