c典型算法 递归

来源:互联网 发布:windows installer 编辑:程序博客网 时间:2024/06/02 16:29

--------------------------------
#include <stdio.h>
#include <stdlib.h>

static int count = 0;

int print( char x,char y) 

printf( "%c ---> %c/n", x, y); 
return ++count;
}


void move(int n,char x,char y,char z)
{
int count=0;
  if(n==1)
  {
   print(x,z);
  }
  else
    {
      move(n-1,y,x,z);
     print(x,z);
     //count++;
     move(n-1,z,y,x);
     // return count;
    }
   
}


void main(void)
{
   int m;
   printf("输入汉诺塔层数:/n");
   scanf("%d",&m);
   move(m,'A','B','C');
   printf("移动了%d次/n",count);
   system("pause");
   
原创粉丝点击