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.

13 "Atlanta", "Miami", "Dallas", "Houston"};<br />

14<br />

15 // Edge array for graph in Figure <strong>25</strong>.1<br />

16 int edges[][3] = {<br />

17 {0, 1, 807}, {0, 3, 1331}, {0, 5, 2097},<br />

18 {1, 0, 807}, {1, 2, 381}, {1, 3, 1267},<br />

19 {2, 1, 381}, {2, 3, 1015}, {2, 4, 1663}, {2, 10, 1435},<br />

20 {3, 0, 1331}, {3, 1, 1267}, {3, 2, 1015}, {3, 4, 599},<br />

21 {3, 5, 1003},<br />

22 {4, 2, 1663}, {4, 3, 599}, {4, 5, 533}, {4, 7, 1260},<br />

23 {4, 8, 864}, {4, 10, 496},<br />

24 {5, 0, 2097}, {5, 3, 1003}, {5, 4, 533},<br />

<strong>25</strong> {5, 6, 983}, {5, 7, 787},<br />

26 {6, 5, 983}, {6, 7, 214},<br />

27 {7, 4, 1260}, {7, 5, 787}, {7, 6, 214}, {7, 8, 888},<br />

28 {8, 4, 864}, {8, 7, 888}, {8, 9, 661},<br />

29 {8, 10, 781}, {8, 11, 810},<br />

30 {9, 8, 661}, {9, 11, 1187},<br />

31 {10, 2, 1435}, {10, 4, 496}, {10, 8, 781}, {10, 11, 239},<br />

32 {11, 8, 810}, {11, 9, 1187}, {11, 10, 239}<br />

33 };<br />

34<br />

35 // 23 undirected edges in Figure <strong>25</strong>.1<br />

36 const int NUMBER_OF_EDGES = 46;<br />

37<br />

38 // Create a vector for vertices<br />

39 vector vectorOfVertices(12);<br />

40 copy(vertices, vertices + 12, vectorOfVertices.begin());<br />

41<br />

42 // Create a vector for edges<br />

43 vector edgeVector;<br />

44 for (int i = 0; i < NUMBER_OF_EDGES; i++)<br />

45 edgeVector.push_back(<strong>Weighted</strong>Edge(edges[i][0],<br />

46 edges[i][1], edges[i][2]));<br />

47<br />

48 <strong>Weighted</strong>Graph graph1(vectorOfVertices, edgeVector);<br />

49 cout

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

Saved successfully!

Ooh no, something went wrong!