Skip to content
This repository was archived by the owner on May 27, 2019. It is now read-only.

Commit a2e1f88

Browse files
committed
Merge branch 'algorithm-result-printing' into development
2 parents bca27d5 + 90d1c52 commit a2e1f88

File tree

4 files changed

+54
-36
lines changed

4 files changed

+54
-36
lines changed

DirectedGraph.cpp

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ string DirectedGraph::runAlgorithm(char index, char arg1, int arg2, int arg3) {
8080

8181
if (index == 1) {
8282
if (arg1 == 0) {
83-
output = dijkstrasAlgorithmOnMatrix(arg2, arg3);
83+
output = dijkstrasAlgorithmOnMatrix(arg2, arg3, true);
8484
} else if (arg1 == 1) {
85-
output = dijkstrasAlgorithmOnList(arg2, arg3);
85+
output = dijkstrasAlgorithmOnList(arg2, arg3, true);
8686
} else {
8787
throw "Nieznany blad!"; // should never be thrown
8888
}
@@ -148,7 +148,7 @@ void DirectedGraph::loadRawDataToList(std::vector<int> rawData) {
148148

149149
// private
150150

151-
std::string DirectedGraph::dijkstrasAlgorithmOnMatrix(int beginVertex, int endVertex) {
151+
std::string DirectedGraph::dijkstrasAlgorithmOnMatrix(int beginVertex, int endVertex, bool print) {
152152
if (incidenceMatrix.size() == 0)
153153
throw "Graf pusty!";
154154

@@ -210,23 +210,28 @@ std::string DirectedGraph::dijkstrasAlgorithmOnMatrix(int beginVertex, int endVe
210210

211211
}
212212

213-
string output;
214-
output = "Najkrotsza droga z wierzch.: " + to_string(beginVertex) + " do wierzch.: " + to_string(endVertex) + " wynosi: " + to_string(pathLength[endVertex]) + ".\n";
215-
output += "Prowadzi nastepujaca droga: ";
213+
if (print) {
214+
string output;
215+
output = "Najkrotsza droga z wierzch.: " + to_string(beginVertex) + " do wierzch.: " + to_string(endVertex) +
216+
" wynosi: " + to_string(pathLength[endVertex]) + ".\n";
217+
output += "Prowadzi nastepujaca droga: ";
218+
219+
currentVertex = endVertex;
216220

217-
currentVertex = endVertex;
221+
output += to_string(currentVertex);
218222

219-
output += to_string(currentVertex);
223+
while (currentVertex != beginVertex) {
224+
currentVertex = previousVertex[currentVertex];
225+
output += " <- " + to_string(currentVertex);
226+
}
220227

221-
while (currentVertex != beginVertex) {
222-
currentVertex = previousVertex[currentVertex];
223-
output += " <- " + to_string(currentVertex);
228+
return output;
224229
}
225230

226-
return output;
231+
return "";
227232
}
228233

229-
std::string DirectedGraph::dijkstrasAlgorithmOnList(int beginVertex, int endVertex) {
234+
std::string DirectedGraph::dijkstrasAlgorithmOnList(int beginVertex, int endVertex, bool print) {
230235
if (adjacencyList.size() == 0)
231236
throw "Graf pusty!";
232237

@@ -282,18 +287,23 @@ std::string DirectedGraph::dijkstrasAlgorithmOnList(int beginVertex, int endVert
282287

283288
}
284289

285-
string output;
286-
output = "Najkrotsza droga z wierzch.: " + to_string(beginVertex) + " do wierzch.: " + to_string(endVertex) + " wynosi: " + to_string(pathLength[endVertex]) + ".\n";
287-
output += "Prowadzi nastepujaca droga: ";
290+
if (print) {
291+
string output;
292+
output = "Najkrotsza droga z wierzch.: " + to_string(beginVertex) + " do wierzch.: " + to_string(endVertex) +
293+
" wynosi: " + to_string(pathLength[endVertex]) + ".\n";
294+
output += "Prowadzi nastepujaca droga: ";
295+
296+
currentVertex = endVertex;
288297

289-
currentVertex = endVertex;
298+
output += to_string(currentVertex);
290299

291-
output += to_string(currentVertex);
300+
while (currentVertex != beginVertex) {
301+
currentVertex = previousVertex[currentVertex];
302+
output += " <- " + to_string(currentVertex);
303+
}
292304

293-
while (currentVertex != beginVertex) {
294-
currentVertex = previousVertex[currentVertex];
295-
output += " <- " + to_string(currentVertex);
305+
return output;
296306
}
297307

298-
return output;
308+
return "";
299309
}

DirectedGraph.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ class DirectedGraph : public Graph {
2525
void loadRawDataToList(std::vector<int> rawData) override ;
2626

2727
private:
28-
std::string dijkstrasAlgorithmOnMatrix(int beginVertex, int endVertex);
29-
std::string dijkstrasAlgorithmOnList(int beginVertex, int endVertex);
28+
std::string dijkstrasAlgorithmOnMatrix(int beginVertex, int endVertex, bool print);
29+
std::string dijkstrasAlgorithmOnList(int beginVertex, int endVertex, bool print);
3030

3131
};
3232

UndirectedGraph.cpp

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ string UndirectedGraph::runAlgorithm(char index, char arg1, int arg2, int arg3)
8282

8383
if (index == 1) {
8484
if (arg1 == 0) {
85-
output = primsAlgorithmOnMatrix();
85+
output = primsAlgorithmOnMatrix(true);
8686
} else if (arg1 == 1) {
87-
output = primsAlgorithmOnList();
87+
output = primsAlgorithmOnList(true);
8888
} else {
8989
throw "Nieznany blad!"; // should never be thrown
9090
}
@@ -151,7 +151,7 @@ void UndirectedGraph::loadRawDataToList(std::vector<int> rawData) {
151151

152152
// private
153153

154-
string UndirectedGraph::primsAlgorithmOnMatrix() {
154+
std::string UndirectedGraph::primsAlgorithmOnMatrix(bool print) {
155155
// prepare vector for output
156156
vector<vector<int>> minimumSpanningTree;
157157

@@ -219,14 +219,18 @@ string UndirectedGraph::primsAlgorithmOnMatrix() {
219219

220220
} while (foundVertices.size() < numberOfVertices);
221221

222-
string output = "Minimalne drzewo rozpinajace\n";
222+
if (print) {
223+
string output = "Minimalne drzewo rozpinajace\n";
223224

224-
output += printMatrix(minimumSpanningTree);
225+
output += printMatrix(minimumSpanningTree);
225226

226-
return output;
227+
return output;
228+
}
229+
230+
return "";
227231
}
228232

229-
string UndirectedGraph::primsAlgorithmOnList() {
233+
std::string UndirectedGraph::primsAlgorithmOnList(bool print) {
230234
// prepare vector for output
231235
std::vector<std::forward_list<EdgeListElement>> minimumSpanningTree;
232236

@@ -273,9 +277,13 @@ string UndirectedGraph::primsAlgorithmOnList() {
273277

274278
} while (foundVertices.size() < numberOfVertices);
275279

276-
string output = "Minimalne drzewo rozpinajace\n";
280+
if (print) {
281+
string output = "Minimalne drzewo rozpinajace\n";
277282

278-
output += printList(minimumSpanningTree);
283+
output += printList(minimumSpanningTree);
279284

280-
return output;
285+
return output;
286+
}
287+
288+
return "";
281289
}

UndirectedGraph.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ class UndirectedGraph : public Graph {
2525
void loadRawDataToList(std::vector<int> rawData) override ;
2626

2727
private:
28-
std::string primsAlgorithmOnMatrix();
29-
std::string primsAlgorithmOnList();
28+
std::string primsAlgorithmOnMatrix(bool print);
29+
std::string primsAlgorithmOnList(bool print);
3030

3131
};
3232

0 commit comments

Comments
 (0)