@@ -118,7 +118,7 @@ void DirectedGraph::test() {
118118 path = " ..\\ wyniki\\ " ;
119119 path += to_string (time (0 ));
120120 path += " -gSkierowany-algorytmDijkstry-n" + to_string (numberOfElements[i]) + " -g" +
121- to_string (density[j]) + " -r" + representationType[k] + " .txt" ;
121+ to_string (density[j]) + " -r" + representationType[k] + " .txt" ;
122122
123123 cout << " Test - Graf: Skierowany - Algorytm: Dijkstry - Ilosc elem: " << numberOfElements[i] << " - Gestosc: " << density[j] << " - Reprezentacja: " << representationType[k] << endl;
124124
@@ -392,25 +392,51 @@ std::string DirectedGraph::dijkstrasAlgorithmOnList(int beginVertex, int endVert
392392 }
393393
394394 if ((i != numberOfVertices - 1 ) && (shortestPathVertex == -1 ))
395- throw " Graf niespojny! " ;
395+ break ;
396396
397397 currentVertex = shortestPathVertex;
398398
399399 }
400400
401401 if (print) {
402402 string output;
403- output = " Najkrotsza droga z wierzch.: " + to_string (beginVertex) + " do wierzch.: " + to_string (endVertex) +
404- " wynosi: " + to_string (pathLength[endVertex]) + " .\n " ;
405- output += " Prowadzi nastepujaca droga: " ;
403+ shortestPath = pathLength[endVertex];
404+
405+ if (shortestPath == ULONG_MAX) {
406+ output += " Droga pomiedzy wybranymi wierzcholkami nie istnieje!\n\n "
407+ } else {
408+ output =
409+ " Najkrotsza droga z wierzch.: " + to_string (beginVertex) + " do wierzch.: " + to_string (endVertex) +
410+ " wynosi: " + to_string (shortestPath) + " .\n " ;
411+ output += " Prowadzi nastepujaca droga: " ;
406412
407- currentVertex = endVertex;
413+ currentVertex = endVertex;
408414
409- output += to_string (currentVertex);
415+ output += to_string (currentVertex);
410416
411- while (currentVertex != beginVertex) {
412- currentVertex = previousVertex[currentVertex];
413- output += " <- " + to_string (currentVertex);
417+ while (currentVertex != beginVertex) {
418+ currentVertex = previousVertex[currentVertex];
419+ output += " <- " + to_string (currentVertex);
420+ }
421+
422+ output += " \n\n " ;
423+ }
424+
425+ output += " Najkrotsza droga do innych wierzcholkow: \n " ;
426+ output += " W | Dlugosc\n " ;
427+ output += " ------------------" ;
428+ for (int i = 0 ; i < numberOfVertices; i++) {
429+ shortestPath = pathLength[i];
430+
431+ output += to_string (i) + " | " ;
432+
433+ if (shortestPath == ULONG_MAX) {
434+ output += " BRAK" ;
435+ } else {
436+ output += to_string (shortestPath);
437+ }
438+
439+ output += " \n " ;
414440 }
415441
416442 return output;
0 commit comments