CHAPTER 25 Weighted Graphs and Applications Objectives ⢠To ...
CHAPTER 25 Weighted Graphs and Applications Objectives ⢠To ...
CHAPTER 25 Weighted Graphs and Applications Objectives ⢠To ...
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
7 {<br />
8 public:<br />
9 double weight; // The weight on edge (u, v)<br />
10<br />
11 // Create a weighted edge on (u, v)<br />
12 <strong>Weighted</strong>Edge(int u, int v, double weight): Edge(u, v)<br />
13 {<br />
14 this->weight = weight;<br />
15 }<br />
16<br />
17 // Compare edges based on weights<br />
18 bool operator=(const <strong>Weighted</strong>Edge& edge) const<br />
34 {<br />
35 return (*this).weight >= edge.weight;<br />
36 }<br />
37<br />
38 bool operator==(const <strong>Weighted</strong>Edge& edge) const<br />
39 {<br />
40 return (*this).weight == edge.weight;<br />
41 }<br />
42<br />
43 bool operator!=(const <strong>Weighted</strong>Edge& edge) const<br />
44 {<br />
45 return (*this).weight != edge.weight;<br />
46 }<br />
47 };<br />
48 #endif<br />
The Edge class, defined in Listing 24.1, represents an edge from vertex u to v. <strong>Weighted</strong>Edge extends<br />
Edge with a new property weight.<br />
<strong>To</strong> create a <strong>Weighted</strong>Edge object, use WeighedEdge(i, j, w), where w is the weight on edge (i,<br />
j). Often you need to compare the weights of the edges. For this reason, we define the operator functions<br />
(=) in the <strong>Weighted</strong>Edge class.<br />
5