Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

몸짱프로젝트/HanoiProblem

From ZeroWiki
Revision as of 05:29, 7 February 2021 by imported>Unknown
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

C++ version

  • 개발자 : 나휘동
  • Recusive Function Call 사용
#include <iostream.h>
void hanoi(const int n, int x, int y, int z);
int count = 0;
void main()
{
	hanoi(4, 1, 2, 3);
	cout << "Steps : " << count << endl;
}

void hanoi(const int n, int x, int y, int z)
{
	if ( n == 1){
		cout << x << "->" << y << endl;
		count++;
	}
	else{
		hanoi(n-1, x, y, z);
		hanoi(1, x, z, y);
		hanoi(n-1, y, z, x);
	}
	
}

몸짱프로젝트