Çó½ân½×HanoiËþÎÊÌâµÄcº¯Êý
#include <stdio.h>
int Count=0;
void move(char x,int n,char z){
printf(" %d. disk %d: %c => %c\n",++Count,n,x,z);
}//move
// ½«Ëþ×ùxÉÏ°´Ö±¾¶ÓÉСµ½´óÇÒ×ÔÉ϶øϱàºÅΪ1ÖÁnµÄn¸öÔ²ÅÌ°´¹æÔò°áµ½Ëþ×ùzÉÏ£¬y¿ÉÓÃ×÷¸¨ÖúËþ×ù
void Hanoi(int n,char x,char y,char z){
if (n==1) move(x,1,z); //½«±àºÅΪ£±µÄÔ²ÅÌ´ÓxÒƵ½z
else{
Hanoi(n-1,x,z,y);
move(x,n,z); //½«±àºÅΪnµÄÔ²ÅÌ´ÓxÒƵ½z
Hanoi(n-1,y,x,z); //½«yÉϱàºÅΪ£±ÖÁn-1µÄÔ²ÅÌÒƵ½z,x×÷¸¨ÖúËþ
}
}//Hanoi
void main(void){
int k;
printf("\nInput n = ");
scanf("%d",&k);
Hanoi(k,'x','y','z');
}//main
Ïà¹ØÎĵµ£º
Ò»¸öÓÉC/C++±àÒëµÄ³ÌÐòÕ¼ÓõÄÄÚ´æ·ÖΪÒÔϼ¸¸ö²¿·Ö
1¡¢Õ»Çø£¨stack£©— ÓɱàÒëÆ÷×Ô¶¯·ÖÅäÊÍ·Å
£¬´æ·Åº¯ÊýµÄ²ÎÊýÖµ£¬¾Ö²¿±äÁ¿µÄÖµµÈ¡£Æä²Ù×÷·½Ê½ÀàËÆÓÚÊý¾Ý½á¹¹ÖеÄÕ»¡£
2¡¢¶ÑÇø£¨heap£© — Ò»°ãÓɳÌÐòÔ±·ÖÅäÊÍ·Å
£¬
Èô³ÌÐòÔ±²»ÊÍ·Å£¬³ÌÐò½áÊøʱ¿ÉÄÜÓÉOS»ØÊÕ ¡£×¢ÒâËüÓëÊý¾Ý½á¹¹ÖеĶÑÊÇÁ½»ØÊ£¬·ÖÅä·½ ......
12.1 λÔËËã·û£ÃÓïÑÔÌṩÁËÁùÖÖλÔËËã·û£º
& °´Î»Óë
| °´Î»»ò
^ &nb ......
ÒýÑÔ
¡¡¡¡Ö¸ÕëÊÇC/C++ÓïÑÔµÄÌØÉ«£¬¶øÊý×éÃûÓëÖ¸ÕëÓÐÌ«¶àµÄÏàËÆ£¬ÉõÖÁºÜ¶àʱºò£¬Êý×éÃû¿ÉÒÔ×÷ΪָÕëʹÓá£ÓÚÊǺõ£¬ºÜ¶à³ÌÐòÉè¼ÆÕ߾ͱ»¸ãºýÍ¿ÁË¡£¶øÐí¶àµÄ´óѧÀÏʦ£¬ËûÃÇÔÚCÓïÑԵĽÌѧ¹ý³ÌÖÐÒ²´íÎóµÃ¸øѧÉú½²½â£º"Êý×éÃû¾ÍÊÇÖ¸Õë"¡£ºÜÐÒÔË£¬ÎҵĴóѧÀÏʦ¾ÍÊÇÆäÖÐÖ®Ò»¡£Ê±ÖÁ½ñÈÕ£¬ÎÒÈÕ¸´Ò»ÈյؽøÐÐ×ÅC/C++ÏîÄ¿µÄ¿ª·¢£¬¶øÉí±ß» ......
#include <stdio.h>
#include <string.h>
#include <math.h>
#define BASE 10
int intlen(long n);
int main()
{
int i, j, num, sz;
i = j = num = sz = 0;
if (!scanf("%d", &num) || num <= 0) {
printf("invalid input\n");
retu ......