-
Notifications
You must be signed in to change notification settings - Fork 1
/
edge.h
114 lines (97 loc) · 2.48 KB
/
edge.h
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/**
* @file edge.h
* Definition and (minimal) implementation of an edge class.
*/
#pragma once
#include "Airport.h"
#include <string>
#include <limits.h>
using std::string;
typedef string Vertex;
/**
* Represents an edge in a graph; used by the Graph class.
*
* @author Sean Massung
* @date Spring 2012
*/
class Edge
{
public:
Vertex source; /**< The source of the edge **/
Vertex dest; /**< The destination of the edge **/
/**
* Parameter constructor for unweighted graphs.
* @param u - one vertex the edge is connected to
* @param v - the other vertex it is connected to
*/
Edge(Vertex u, Vertex v)
: source(u), dest(v), label(""), weight(-1)
{ /* nothing */
}
/**
* Parameter constructor for unweighted graphs.
* @param u - one vertex the edge is connected to
* @param v - the other vertex it is connected to
* @param lbl - the edge label
*/
Edge(Vertex u, Vertex v, string lbl)
: source(u), dest(v), label(lbl), weight(-1)
{ /* nothing */
}
/**
* Parameter constructor for weighted graphs.
* @param u - one vertex the edge is connected to
* @param v - the other vertex it is connected to
* @param w - the weight of the edge
* @param lbl - the edge label
*/
Edge(Vertex u, Vertex v, int w, string lbl)
: source(u), dest(v), label(lbl), weight(w)
{ /* nothing */
}
/**
* Default constructor.
*/
Edge() : source(), dest(), label(""), weight(-1)
{ /* nothing */
}
/**
* Compares two Edges.
* operator< is defined so Edges can be sorted with std::sort.
* @param other - the edge to compare with
* @return whether the current edge is less than the parameter
*/
bool operator<(const Edge& other) const
{
return weight < other.weight;
}
/**
* Gets edge label.
*/
string getLabel() const
{
return this->label;
}
/**
* Gets edge weight.
*/
int getWeight() const
{
return this->weight;
}
/**
* Compares two edges' source and dest.
* @param other - the edge to compare with
*/
bool operator==(Edge& other) const
{
if (this->source != other.source)
return false;
if (this->dest != other.dest)
return false;
return true;
}
private:
string label; /**< The edge label **/
int weight; /**< The edge weight (if in a weighed graph) **/
};