21.11.2014 Views

CHAPTER 25 Weighted Graphs and Applications Objectives • To ...

CHAPTER 25 Weighted Graphs and Applications Objectives • To ...

CHAPTER 25 Weighted Graphs and Applications Objectives • To ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

The getNumberOfFlips(int u) function (lines 62–72) returns the number of flips from node u to<br />

the target node, which is the cost of the path from node u to the target node. This cost can be obtained by<br />

invoking the getCost(u) function defined in the ShortestPathTree class (line 76).<br />

Listing <strong>25</strong>.11 gives a program that prompts the user to enter an initial node <strong>and</strong> displays the minimum<br />

number of flips to reach the target node.<br />

Listing <strong>25</strong>.11 <strong>Weighted</strong>NineTail.cpp<br />

1 #include <br />

2 #include <br />

3 #include "<strong>Weighted</strong>NineTailModel.h"<br />

4 using namespace std;<br />

5<br />

6 int main()<br />

7 {<br />

8 // Prompt the user to enter nine coins H <strong>and</strong> T's<br />

9 cout > initialNode[i];<br />

14<br />

15 cout

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!