@@ -33,39 +33,9 @@ string Graph::printIncidenceMatrix() {
3333
3434string Graph::printAdjacencyList () {
3535 string output = getName ();
36- string temp = " " ;
37-
38- if (adjacencyList.size () == 0 ) {
39- output = " Graf pusty!" ;
40- return output;
41- }
42-
43- output += " \n W || wierzcholek konca krawedzi, waga | kolejna... | ...\n " ; // pierwsza linijka
44-
45- // druga linijka rozdzielajaca
46- for (int i = 0 ; i < 80 ; i++) {
47- output += " -" ;
48- }
4936 output += " \n " ;
5037
51- for (int i = 0 ; i < adjacencyList.size (); i++) {
52- // pierwsza pozycja kolejnej linijki
53- temp = to_string (i);
54-
55- output += " " ;
56- for (int j = 0 ; j < 5 - temp.size (); j++) {
57- if (temp.size () > 5 ) break ;
58- output += " " ;
59- }
60- output += temp + " ||" ;
61-
62- // kolejne pozycje
63- for (auto & element : adjacencyList[i]) {
64- output += " " + to_string (element.edgeEnd ) + " , " + to_string (element.value ) + " |" ;
65- }
66-
67- output += " \n " ;
68- }
38+ output += printList (adjacencyList);
6939
7040 return output;
7141}
@@ -182,3 +152,42 @@ std::string Graph::printMatrix(vector<vector<int>> v) {
182152
183153 return output;
184154}
155+
156+ std::string Graph::printList (vector<forward_list<Graph::EdgeListElement>> v) {
157+ string output = " " ;
158+ string temp = " " ;
159+
160+ if (v.size () == 0 ) {
161+ output = " Graf pusty!" ;
162+ return output;
163+ }
164+
165+ output += " W || wierzcholek konca krawedzi, waga | kolejna... | ...\n " ; // pierwsza linijka
166+
167+ // druga linijka rozdzielajaca
168+ for (int i = 0 ; i < 80 ; i++) {
169+ output += " -" ;
170+ }
171+ output += " \n " ;
172+
173+ for (int i = 0 ; i < v.size (); i++) {
174+ // pierwsza pozycja kolejnej linijki
175+ temp = to_string (i);
176+
177+ output += " " ;
178+ for (int j = 0 ; j < 5 - temp.size (); j++) {
179+ if (temp.size () > 5 ) break ;
180+ output += " " ;
181+ }
182+ output += temp + " ||" ;
183+
184+ // kolejne pozycje
185+ for (auto & element : v[i]) {
186+ output += " " + to_string (element.edgeEnd ) + " , " + to_string (element.value ) + " |" ;
187+ }
188+
189+ output += " \n " ;
190+ }
191+
192+ return output;
193+ }
0 commit comments