From 1d54efe2781b7dfd85fccbc1d2fa31931e14c54f Mon Sep 17 00:00:00 2001 From: Patrice Matz Date: Thu, 2 Jan 2020 23:28:08 +0100 Subject: [PATCH] Update hanoi.cpp --- hanoi.cpp | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/hanoi.cpp b/hanoi.cpp index 085cc4a..486761f 100644 --- a/hanoi.cpp +++ b/hanoi.cpp @@ -12,31 +12,26 @@ hanoi::hanoi(int k) { bauen(h); } -void hanoi::setze(int h, int v, int n, int m) -{ +void hanoi::setze(int h, int v, int n, int m) { if (h != 0) { setze(h - 1, v, m, n); cout << " " << v << " - " << n << endl; this->leg(v, n); this->print(); setze(h - 1, m, n, v); - } } -void hanoi::setze_fast(int h, int v, int n, int m) -{ +void hanoi::setze_fast(int h, int v, int n, int m) { if (h != 0) { setze_fast(h - 1, v, m, n); this->leg(v, n); setze_fast(h - 1, m, n, v); - } } void hanoi::bauen(int h) { - for (int k = 0; k <= h; k++) - { + for (int k = 0; k <= h; k++) { turm1[k] = h-k+1; turm2[k] = 0; turm3[k] = 0; @@ -47,13 +42,10 @@ void hanoi::print() { for (int i = h; i >= 0; i--) { if (i <= h1 && turm1[i]) cout << turm1[i] << "\t"; else cout << " " << "\t"; - if (i <= h2 && turm2[i]) cout << turm2[i] << "\t"; else cout << " " << "\t"; - if (i <= h3 && turm3[i]) cout << turm3[i] << "\t"; else cout << " " << "\t"; - cout << endl; } cout << "##################" << endl; @@ -62,10 +54,8 @@ void hanoi::print() { void hanoi::leg(int v, int n) { if (v == 1 && n == 2 && h1 >= 0) turm2[++h2] = turm1[h1--]; if (v == 1 && n == 3 && h1 >= 0) turm3[++h3] = turm1[h1--]; - if (v == 2 && n == 1 && h2 >= 0) turm1[++h1] = turm2[h2--]; if (v == 2 && n == 3 && h2 >= 0) turm3[++h3] = turm2[h2--]; - if (v == 3 && n == 1 && h3 >= 0) turm1[++h1] = turm3[h3--]; if (v == 3 && n == 2 && h3 >= 0) turm2[++h2] = turm3[h3--]; }