#include <time.h>
void hannota(int n,char ta1,char ta2,char ta3)
void main()
{
int n
clock_t begin, duration
printf("让郑键input the number of diskes:")
scanf("%d",&n)
begin = clock()
hannota(n,'坦巧1','2','3')
duration = clock() - begin
printf( "用时约: %d毫丛虚秒", duration*1000 / CLOCKS_PER_SEC )
printf("\n")
}
void hannota(int n,char ta1,char ta2,char ta3)
{
if(n==1)
printf("%c--->%c",ta1 ,ta2)
else
{
hannota(n-1,ta1,ta3,ta2)
printf("%c---->%c",ta1,ta2)
hannota(n-1,ta3,ta2,ta1)
}
}
运行时耗时是一样的,我觉着为了编译连接时省一点时间而去重敲代码太不划算了,即使是复制也没不划算,更蠢斗何况如果是新手,你也编不出来什么更知拿好的函数,一般来讲是编不出来的,用定义好的省时省力省搭档搭事。欢迎分享,转载请注明来源:内存溢出
评论列表(0条)