U E D R , A S I H C RSS

몸짱프로젝트/Hanoi Problem

C++ version

  • 개발자 : 나휘동
  • Recusive Function Call 사용

~cpp 
#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);
	}
	
}


Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:29:28
Processing time 0.0113 sec