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

Commit 30b6494

Browse files
committed
Make method for printing list print any list
1 parent 0e687e5 commit 30b6494

2 files changed

Lines changed: 41 additions & 31 deletions

File tree

Graph.cpp

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -33,39 +33,9 @@ string Graph::printIncidenceMatrix() {
3333

3434
string 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+
}

Graph.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class Graph {
6060
bool edgeEndAvailable(int beginning, int end);
6161

6262
std::string printMatrix(std::vector<std::vector<int>> v);
63+
std::string printList(std::vector<std::forward_list<EdgeListElement>> v);
6364

6465
};
6566

0 commit comments

Comments
 (0)