-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathigraph.h
59 lines (50 loc) · 1.31 KB
/
igraph.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
//
// igraph.h
// p5
//
// Kyle C. Arthur C.
//
#ifndef igraph_h
#define igraph_h
#include <algorithm>
#include <vector>
#include <string>
#include <unordered_map>
#include <limits>
using namespace std;
class IGraph{
public:
int numVertex, numEdge;
int numComponent, largestComponent, largestDegree;
IGraph() :
numVertex(0),numEdge(0),
numComponent(0),largestComponent(0),largestDegree(0){};
~IGraph(){};
void insert(const string);
bool contains(const string);
void printNeighbor(const string);
//calculate number of components
void getComponent();
int getDegree(const string);
int getEccentricity(const string);
//stop searching as soon as it find the path
int shortestPath(const string, const string);
void printShortestPath(const string, const string);
private:
//adjacency list
vector<vector<int> > nodeList;
//map string into its index in the nodeList
unordered_map<string, int> indexMap;
//keep track of all words
vector<string> wordList;
vector<bool> color;
vector<int> d;
vector<int> pred;
//check whether string has one different char than this
bool checkNeighbor(const string, const string);
void bfs(const string w, const string target = "");
//return number of nodes visited during bfs
int bfs(int s1, int s2 = -1);
void bfsReset();
};
#endif /* igraph_h */