99
1010#define INF 99999
1111
12- Graph::Graph (int numberOfVertices) {
12+ Graph::Graph (int numberOfVertices,AdjacencyMatrix adjacencyMatrix ) {
1313 this ->numberOfVertices = numberOfVertices;
14+ this ->adjacencyMatrix = adjacencyMatrix;
1415 this ->numberOfEdges =0 ;
16+ createNodes (numberOfVertices);
17+ createEdges (adjacencyMatrix);
1518}
1619
1720
@@ -98,11 +101,9 @@ vector<GraphEdge> *Graph::dijkstraAlgorithm(GraphNode *node) {
98101 }
99102 }
100103 for (int j = 0 ; j < numberOfVertices; ++j) {
101-
102104 cout<<" Path to Node " <<j<<" is " ;
103105 printParents (j,node->getNodeIndex (),parentVertices);
104106 cout<<endl;
105-
106107 }
107108
108109 return edgesShortestPath;
@@ -123,21 +124,17 @@ int Graph::getNumberOfVertices() {
123124 return numberOfVertices;
124125}
125126
126- vector<GraphNode *> * Graph::createNodes (int numberOfVertices) {
127- vector<GraphNode*>* vector1=new vector<GraphNode*>();
127+ void Graph::createNodes (int numberOfVertices) {
128128 for (int i = 0 ; i < numberOfVertices; ++i) {
129- vector1-> push_back ( this -> addNode (i) );
129+ addNode (i);
130130 }
131- return vector1;
132-
133131}
134132
135- void Graph::createEdges (vector<GraphNode *> *nodes,vector<vector<int >> matrix ) {
136-
133+ void Graph::createEdges (vector<vector<int >> matrix ) {
137134 for (int i = 0 ; i < numberOfVertices; ++i) {
138135 for (int j = 0 ; j < numberOfVertices; ++j) {
139136 if (matrix[i][j]!=0 )
140- this ->addEdge (nodes-> at ((unsigned long ) i), nodes-> at ((unsigned long ) j), matrix[i][j]);
137+ this ->addEdge (vertices. at ((unsigned long ) i), vertices. at ((unsigned long ) j), matrix[i][j]);
141138 }
142139
143140 }
0 commit comments