-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgraphm.h
65 lines (50 loc) · 1.96 KB
/
graphm.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
// --------------------- graphm.h -----------------------------------------
//
// Shyawn Karim, CSS 343
// Created: October 26, 2015
// Last Modified: Novemeber 12, 2015
// --------------------------------------------------------------
// Purpose: Implement Dijkstra's shortest path algorithm by reading in a
// data file consisting of many lines and be able to find the lowest cost
// paths. Then display the cost and path from every node to to every
// other node.
// --------------------------------------------------------------
// Assumptions: All input data is assumed to be correctly formatted
// and valid.
// --------------------------------------------------------------
#ifndef DIJKSTRASSHORTESTPATH_GRAPHM_H
#define DIJKSTRASSHORTESTPATH_GRAPHM_H
#include "nodedata.h"
#include <fstream>
#include <iostream>
using namespace std;
int const MAXNODES_M = 101; // constant size for T and C table
class GraphM
{
public:
// Constructor
GraphM();
// Functions
void buildGraph(ifstream&);
void findShortestPath();
bool insertEdge(int from, int to, int dist);
bool removeEdge(int from, int to);
void display(int from, int to);
void displayAll();
private:
struct TableType
{
bool visited; // whether node has been visited
int dist; // shortest distance from source known so far
int path; // previous node in path of min dist
};
NodeData data[MAXNODES_M]; // data for graph nodes
int C[MAXNODES_M][MAXNODES_M]; // cost array, the adjacency matrix
int size; // number of nodes in the graph
TableType T[MAXNODES_M][MAXNODES_M]; // stores visited, distance, path
// helper for display()
void findData(int from, int to);
// helper for display() and displayAll()
void findPath(int from, int to);
};
#endif //DIJKSTRASSHORTESTPATH_GRAPHM_H