-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
52 lines (44 loc) · 1.93 KB
/
main.cpp
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
#include "Graph.h"
void printNeighborList(List* neighboorArray, int size, int start, int end);
void printDistancesArray(int* d, int size );
void main() {
Graph g ;
g.ReadGraph();
int* distanceArrayG = g.BFS(g.GetStart());
int* d = g.BFS(g.GetStart());
//cout << "Printing NeighborList:" << endl;
//printNeighborList(g.GetVerticesArray(), g.GetNumOfVertices());
//printDistancesArray(distanceArrayG, g.GetNumOfVertices());
//cout << "Printing NeighborList after RemoveRedundantEdges :" << endl;
g.RemoveRedundantEdges(distanceArrayG);
//printNeighborList(g.GetVerticesArray(), g.GetNumOfVertices());
//cout << "Printing H(G Transpose) NeighborList :" << endl;
Graph H = g.Transpose();
//printNeighborList(H.GetVerticesArray(), g.GetNumOfVertices());
//cout << "Printing DistanceArray after BFS :" << endl;
int* distanceArrayH = H.BFS(g.GetEnd());
//printDistancesArray(distanceArrayH, g.GetNumOfVertices());
//cout << "Printing H(G Transpose) NeighborList after RemoveUnreachableEdges :" << endl;
H.RemoveUnreachableEdges(distanceArrayH);
//printNeighborList(H.GetVerticesArray(), g.GetNumOfVertices());
cout << "Printing final graph NeighborList after all:" << endl;
Graph FinalGraph = H.Transpose();
printNeighborList(FinalGraph.GetVerticesArray(), g.GetNumOfVertices() , g.GetStart() , g.GetEnd());
}
void printNeighborList(List* neighboorArray, int size , int start , int end ) {
ListNode* currVertex = neighboorArray[start].GetListHead();
while (currVertex != nullptr) {
ListNode* currNeighbor = currVertex->next;
while (currNeighbor != nullptr) {
cout << (currVertex->vertex) << "\t" << (currNeighbor->vertex) << endl;
currNeighbor = currNeighbor->next;
}
currVertex = currVertex->next;
}
}
void printDistancesArray(int* d , int size) {
cout << "Distance array -->" << endl;
for (int i = 1; i <= size; i++) {
cout << "d" << "[" << i << "]" << d[i] << endl;
}
}