@@ -24,61 +24,9 @@ int Graph::getNumberOfAvailableAlgorithms() {
2424
2525string Graph::printIncidenceMatrix () {
2626 string output = getName ();
27- string temp = " " ;
28-
29- if (incidenceMatrix.size () == 0 ) {
30- output = " Graf pusty!" ;
31- return output;
32- }
33-
34- output += " \n K\\ W ||" ; // lewy gorny rog ma ' K\W ||', podwojny | dla wyroznienia komorki
35-
36- // wypisz pierwsza linijke
37- for (int i = 0 ; i < incidenceMatrix[0 ].size (); i++) {
38- temp = to_string (i);
39-
40- output += " " ;
41- for (int j = 0 ; j < 5 - temp.size (); j++) { // miejsce na 6 znakow dla kazdej komorki
42- if (temp.size () > 5 ) break ;
43- output += " " ;
44- }
45- output += temp + " |" ;
46- }
4727 output += " \n " ;
4828
49- // pozioma linia dla odzielenia wierszy
50- int firstLineSize = output.size () - getName ().size () - 2 ; // -2 bo dwa razy \n
51- for (int i = 0 ; i < firstLineSize; i++) {
52- output += " -" ;
53- }
54- output += " \n " ;
55-
56- // wypisz kolejne linijki
57- for (int i = 0 ; i < incidenceMatrix.size (); i++) {
58- // pierwsza pozycja kolejnej linijki
59- temp = to_string (i);
60-
61- output += " " ;
62- for (int j = 0 ; j < 5 - temp.size (); j++) {
63- if (temp.size () > 5 ) break ;
64- output += " " ;
65- }
66- output += temp + " ||" ;
67-
68- // kolejne pozycje kolejnych linijek
69- for (int j = 0 ; j < incidenceMatrix[0 ].size (); j++) {
70- temp = to_string (incidenceMatrix[i][j]);
71-
72- output += " " ;
73- for (int k = 0 ; k < 5 - temp.size (); k++) {
74- if (temp.size () > 5 ) break ;
75- output += " " ;
76- }
77- output += temp + " |" ;
78- }
79-
80- output += " \n " ;
81- }
29+ output += printMatrix (incidenceMatrix);
8230
8331 return output;
8432}
@@ -173,3 +121,64 @@ bool Graph::edgeEndAvailable(int beginning, int end) {
173121 }
174122 return true ;
175123}
124+
125+ std::string Graph::printMatrix (vector<vector<int >> v) {
126+ string output = " " ;
127+ string temp = " " ;
128+
129+ if (v.size () == 0 ) {
130+ output = " Graf pusty!" ;
131+ return output;
132+ }
133+
134+ output += " K\\ W ||" ; // lewy gorny rog ma ' K\W ||', podwojny | dla wyroznienia komorki
135+
136+ // wypisz pierwsza linijke
137+ for (int i = 0 ; i < v[0 ].size (); i++) {
138+ temp = to_string (i);
139+
140+ output += " " ;
141+ for (int j = 0 ; j < 5 - temp.size (); j++) { // miejsce na 6 znakow dla kazdej komorki
142+ if (temp.size () > 5 ) break ;
143+ output += " " ;
144+ }
145+ output += temp + " |" ;
146+ }
147+ output += " \n " ;
148+
149+ // pozioma linia dla odzielenia wierszy
150+ int firstLineSize = output.size () - 1 ; // -1 bo \n
151+ for (int i = 0 ; i < firstLineSize; i++) {
152+ output += " -" ;
153+ }
154+ output += " \n " ;
155+
156+ // wypisz kolejne linijki
157+ for (int i = 0 ; i < v.size (); i++) {
158+ // pierwsza pozycja kolejnej linijki
159+ temp = to_string (i);
160+
161+ output += " " ;
162+ for (int j = 0 ; j < 5 - temp.size (); j++) {
163+ if (temp.size () > 5 ) break ;
164+ output += " " ;
165+ }
166+ output += temp + " ||" ;
167+
168+ // kolejne pozycje kolejnych linijek
169+ for (int j = 0 ; j < v[0 ].size (); j++) {
170+ temp = to_string (v[i][j]);
171+
172+ output += " " ;
173+ for (int k = 0 ; k < 5 - temp.size (); k++) {
174+ if (temp.size () > 5 ) break ;
175+ output += " " ;
176+ }
177+ output += temp + " |" ;
178+ }
179+
180+ output += " \n " ;
181+ }
182+
183+ return output;
184+ }
0 commit comments