summaryrefslogtreecommitdiff
path: root/cpp/hanoi.cc
diff options
context:
space:
mode:
authorSanto Cariotti <sancn@live.com>2017-04-26 16:37:39 +0200
committerSanto Cariotti <sancn@live.com>2017-04-26 16:37:39 +0200
commit483d63fa7249ad8d6020680c48c3cf6df35010b3 (patch)
tree2f8649e3ae6b42ace5011246285c9c450f004222 /cpp/hanoi.cc
parent6c957dc4e01aee6ce9cae3c8342d04b0fd9ca9c4 (diff)
Moved all C++ files into CPP folder
Diffstat (limited to 'cpp/hanoi.cc')
-rw-r--r--cpp/hanoi.cc29
1 files changed, 29 insertions, 0 deletions
diff --git a/cpp/hanoi.cc b/cpp/hanoi.cc
new file mode 100644
index 0000000..b401060
--- /dev/null
+++ b/cpp/hanoi.cc
@@ -0,0 +1,29 @@
+// ConsoleApplication1.cpp : definisce il punto di ingresso dell'applicazione console.
+//
+#include "stdafx.h"
+#include <iostream>
+
+using namespace std;
+
+static unsigned long int tot = 0;
+
+void hanoi(int d, int inizio, int fine, int transito)
+{
+ if (d == 1);
+ else {
+ hanoi(d - 1, inizio, transito, fine);
+ hanoi(d - 1, transito, fine, inizio);
+ }
+ tot++;
+}
+
+int main()
+{
+ int dischi;
+ cout << "Numero dischi: ";
+ cin >> dischi;
+
+ hanoi(dischi, 1, 3, 2);
+ cout << "In totale: " << tot << " mosse" << endl;
+ return 0;
+}