From f01e030335439cdb643b8055355acca150797472 Mon Sep 17 00:00:00 2001 From: Abhishek Date: Wed, 28 Jul 2021 00:07:27 +0530 Subject: [PATCH] chore(CPlusPlus): added tower of hanoi in recursion (#394) --- algorithms/CPlusPlus/README.md | 3 +++ .../CPlusPlus/Recursion/towerofHanoi.cpp | 22 +++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 algorithms/CPlusPlus/Recursion/towerofHanoi.cpp diff --git a/algorithms/CPlusPlus/README.md b/algorithms/CPlusPlus/README.md index 1caab779..e29f3a33 100644 --- a/algorithms/CPlusPlus/README.md +++ b/algorithms/CPlusPlus/README.md @@ -102,3 +102,6 @@ 2. [Prime Number](Maths/prime-check.cpp) 3. [Prime Sieve](Maths/prime-sieve.cpp) 4. [Fibonacci Series](Maths/fibonaccci-series.cpp) + +# Recursion +1. [Tower of Hanoi](Recursion/towerofHanoi.cpp) diff --git a/algorithms/CPlusPlus/Recursion/towerofHanoi.cpp b/algorithms/CPlusPlus/Recursion/towerofHanoi.cpp new file mode 100644 index 00000000..e3cad42f --- /dev/null +++ b/algorithms/CPlusPlus/Recursion/towerofHanoi.cpp @@ -0,0 +1,22 @@ +#include +#include +using namespace std; + +void towerOfHanoi(int disks,char stand1,char stand2,char stand3) +{ + if(disks==1) + {cout<<"Move disk 1 from "<>n; + towerOfHanoi(n,'A','B','C'); +} \ No newline at end of file