summaryrefslogtreecommitdiff
path: root/graph/euler.cpp
diff options
context:
space:
mode:
authorPaul Jungeblut <paul.jungeblut@gmail.com>2015-12-03 01:12:26 +0100
committerPaul Jungeblut <paul.jungeblut@gmail.com>2015-12-03 01:12:26 +0100
commit53e7f12d828bb94c05d2b6c4e04d61de9482c426 (patch)
tree6621c2c8f537de6527a6e5354539081b79610399 /graph/euler.cpp
parentb9e7427d720b489fa8d712a0ab6e8baa1dcca6be (diff)
Improving graoh chapter.
Diffstat (limited to 'graph/euler.cpp')
-rw-r--r--graph/euler.cpp15
1 files changed, 8 insertions, 7 deletions
diff --git a/graph/euler.cpp b/graph/euler.cpp
index 74b3399..6551ac3 100644
--- a/graph/euler.cpp
+++ b/graph/euler.cpp
@@ -1,3 +1,4 @@
+// Laufzeit: O(|V|+|E|)
vector< vector<int> > adjlist;
vector< vector<int> > otherIdx;
vector<int> cycle;
@@ -14,9 +15,9 @@ void swapEdges(int n, int a, int b) { // Vertauscht Kanten mit Indizes a und b v
otherIdx[neighB][idxNeighB] = a;
}
-void removeEdge(int n, int i) { // Entfernt Kante i von Knoten n (und die zugehoerige Rueckwaertskante).
+void removeEdge(int n, int i) { // Entfernt Kante i von Knoten n (und die zugehörige Rückwärtskante).
int other = adjlist[n][i];
- if (other == n) { //Schlingen
+ if (other == n) { //Schlingen.
validIdx[n]++;
return;
}
@@ -28,14 +29,14 @@ void removeEdge(int n, int i) { // Entfernt Kante i von Knoten n (und die zugeho
validIdx[other]++;
}
-//findet Eulerzyklus an Knoten n startend
-//teste vorher, dass Graph zusammenhaengend ist! (isolierte Punkte sind ok)
-//teste vorher, ob Eulerzyklus ueberhaupt existiert!
+// Findet Eulerzyklus an Knoten n startend.
+// Teste vorher, dass Graph zusammenhängend ist! Was ist mit isolierten Knoten?
+// Teste vorher, ob Eulerzyklus überhaupt existiert!
void euler(int n) {
while (validIdx[n] < (int)adjlist[n].size()) {
int nn = adjlist[n][validIdx[n]];
removeEdge(n, validIdx[n]);
euler(nn);
}
- cycle.push_back(n); //Zyklus am Ende in cycle
-} \ No newline at end of file
+ cycle.push_back(n); // Zyklus am Ende in cycle (umgekehrte Reihenfolge).
+}