-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
44 lines (35 loc) · 1.32 KB
/
Copy pathmain.cpp
File metadata and controls
44 lines (35 loc) · 1.32 KB
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
#include "cGraph.h"
#include "cNode.h"
#include <iostream>
using namespace std;
int main()
{
//Create a graph
cGraph* pGraph = new cGraph();
//populate nodes of the graph
cNode* pNodeA = pGraph->createNode("A");
cNode* pNodeB = pGraph->createNode("B");
cNode* pNodeC = pGraph->createNode("C");
cNode* pNodeD = pGraph->createNode("D");
cNode* pNodeE = pGraph->createNode("E");
//create edge links between nodes
cEdge* pEdgeAB = pNodeA->createEdge( 1, pNodeB );
cEdge* pEdgeBA = pNodeB->createEdge( 5, pNodeA );
cEdge* pEdgeAC = pNodeA->createEdge( 2, pNodeC );
cEdge* pEdgeCA = pNodeC->createEdge( 2, pNodeA );
cEdge* pEdgeCB = pNodeC->createEdge( 1, pNodeB );
cEdge* pEdgeBC = pNodeB->createEdge( 3, pNodeC );
cEdge* pEdgeCD = pNodeC->createEdge( 2, pNodeD );
cEdge* pEdgeDC = pNodeD->createEdge( 2, pNodeC );
cEdge* pEdgeAD = pNodeA->createEdge( 4, pNodeD );
cout << "-= Example using Dijkstra's Algorithm to calculate paths between connected nodes =-\n";
//find a path between 2 nodes
pGraph->findPath( pNodeA, pNodeD );
//find a path between 2 nodes
pGraph->findPath( pNodeD, pNodeA );
//find a path between 2 nodes
pGraph->findPath( pNodeA, pNodeE );
//find a path between 2 nodes
pGraph->findPath( pNodeA, pNodeA );
return 0;
}