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

Commit 87512fc

Browse files
committed
Make all algorithms return string
1 parent 1cd2aef commit 87512fc

7 files changed

Lines changed: 23 additions & 13 deletions

File tree

DirectedGraph.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ void DirectedGraph::generate(int numberOfVertices, int density) {
7474

7575
}
7676

77-
void DirectedGraph::runAlgorithm(char index, char arg1, int arg2, int arg3) {
77+
string DirectedGraph::runAlgorithm(char index, char arg1, int arg2, int arg3) {
7878
if (index == 1) {
7979
if (arg1 == 0) {
8080
dijkstrasAlgorithmOnMatrix();

DirectedGraph.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class DirectedGraph : public Graph {
1616

1717
void generate(int numberOfVertices, int density) override;
1818

19-
void runAlgorithm(char index, char arg1, int arg2, int arg3) override;
19+
std::string runAlgorithm(char index, char arg1, int arg2, int arg3) override;
2020

2121
void test() override;
2222

Graph.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class Graph {
4545

4646
virtual void generate(int numberOfVertices, int density)= 0;
4747

48-
virtual void runAlgorithm(char index, char arg1, int arg2, int arg3)= 0;
48+
virtual std::string runAlgorithm(char index, char arg1, int arg2, int arg3)= 0;
4949

5050
virtual void test()= 0;
5151

Program.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ void Program::start() {
2121
string matrix;
2222
string list;
2323
char index;
24+
string result;
2425

2526
do {
2627
printGraphTypeSelect();
@@ -111,7 +112,8 @@ void Program::start() {
111112
case '9':
112113
index = option2 - 53;
113114
try {
114-
runAlgorithm(index);
115+
result = runAlgorithm(index);
116+
cout << result << endl;
115117
} catch (const char* e) {
116118
cerr << e << endl;
117119
}
@@ -163,12 +165,14 @@ void Program::printGraphMenu() {
163165
cout << "Podaj opcje: ";
164166
}
165167

166-
void Program::runAlgorithm(char index) {
168+
string Program::runAlgorithm(char index) {
167169
string arg1s;
168170
char arg1;
169171
int arg2;
170172
int arg3;
171173

174+
string output;
175+
172176
if (graph->getNumberOfAvailableAlgorithms() > index - 1) {
173177
cout << "Podaj argument 1: ";
174178
cin >> arg1s;
@@ -198,8 +202,10 @@ void Program::runAlgorithm(char index) {
198202
cerr << "Bledna wartosc! Podaj argument 3: ";
199203
}
200204

201-
graph->runAlgorithm(index, arg1, arg2, arg3);
205+
output = graph->runAlgorithm(index, arg1, arg2, arg3);
202206
} else {
203207
cerr << "Nie ma takiej opcji, wybierz jeszcze raz." << endl;
204208
}
209+
210+
return output;
205211
}

Program.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Program {
2121

2222
void printGraphMenu();
2323

24-
void runAlgorithm(char index);
24+
std::string runAlgorithm(char index);
2525
};
2626

2727

UndirectedGraph.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,22 @@ void UndirectedGraph::generate(int numberOfVertices, int density) {
7777
}
7878
}
7979

80-
void UndirectedGraph::runAlgorithm(char index, char arg1, int arg2, int arg3) {
80+
string UndirectedGraph::runAlgorithm(char index, char arg1, int arg2, int arg3) {
81+
string output;
82+
8183
if (index == 1) {
8284
if (arg1 == 0) {
83-
primsAlgorithmOnMatrix();
85+
output = primsAlgorithmOnMatrix();
8486
} else if (arg1 == 1) {
85-
primsAlgorithmOnList();
87+
output = primsAlgorithmOnList();
8688
} else {
8789
throw "Nieznany blad!"; // should never be thrown
8890
}
8991
} else {
9092
throw "Algorytm nie istnieje!";
9193
}
94+
95+
return output;
9296
}
9397

9498
void UndirectedGraph::test() {
@@ -218,6 +222,6 @@ string UndirectedGraph::primsAlgorithmOnMatrix() {
218222
return output;
219223
}
220224

221-
void UndirectedGraph::primsAlgorithmOnList() {
225+
string UndirectedGraph::primsAlgorithmOnList() {
222226
throw "Algorytm jeszcze nie zaimplementowany!";
223227
}

UndirectedGraph.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class UndirectedGraph : public Graph {
1616

1717
void generate(int numberOfVertices, int density) override;
1818

19-
void runAlgorithm(char index, char arg1, int arg2, int arg3) override;
19+
std::string runAlgorithm(char index, char arg1, int arg2, int arg3) override;
2020

2121
void test() override;
2222

@@ -26,7 +26,7 @@ class UndirectedGraph : public Graph {
2626

2727
private:
2828
std::string primsAlgorithmOnMatrix();
29-
void primsAlgorithmOnList();
29+
std::string primsAlgorithmOnList();
3030

3131
};
3232

0 commit comments

Comments
 (0)