Çó½â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»ØÊÕ ¡£×¢ÒâËüÓëÊý¾Ý½á¹¹ÖеĶÑÊÇÁ½»ØÊ£¬·ÖÅä·½ ......
¿ÉϧMS-DOS²»ÊÇÖйúÈËдµÄ£¬²»Ö§³ÖÖÐÎÄ¡£
/* Note:Your choice is C IDE */
#include "stdio.h"
main(int argc, char *argv[])
{
FILE *fp;
char ch;
int num=0,max;
int line=0;
if((fp=fopen(argv[1],"rt"))==NULL)
{
printf("\nCannot open file strike any key exit!");
getch();
exit(1);
......
ÎÒÓõÄÊÇubuntu²Ù×÷ϵͳ¡£´ò¿ªÖÕ¶Ë
1.sudo apt-get install vim(vim-full Õâ¸öÈí¼þ×Ô9.10°æ±¾±»·ÏÆúÁË£¬²»ÂÛÔõôÌí¼ÓÈí¼þÔ´¶¼ÕÒ²»µ½µÄ£¬ËùÒÔÖ±½Ó°²×°vim¾Í¿ÉÒÔÁË£¬£¬Ò²¿ÉÒÔ°²×°gvim£¬£¬ÔÚÐÂÁ¢µÃÈí¼þÀïÃæËÑË÷vim¾Í¿ÉÒÔÕÒµ½ÁË)
2.
sudo apt-get install build-essential // build-essentialÊÇcÓïÑԵĿª·¢°ü£¬°üº¬ÁËgcc ma ......
¡¡¡¡Ëã·¨£¨Algorithm£©£º¼ÆËã»ú½âÌâµÄ»ù±¾Ë¼Ïë·½·¨ºÍ²½Öè¡£Ëã·¨µÄÃèÊö£ºÊǶÔÒª½â¾öÒ»¸öÎÊÌâ»òÒªÍê³ÉÒ»ÏîÈÎÎñËù²ÉÈ¡µÄ·½·¨ºÍ²½ÖèµÄÃèÊö£¬°üÀ¨ÐèҪʲôÊý¾Ý£¨ÊäÈëʲôÊý¾Ý¡¢Êä³öʲô½á¹û£©¡¢²ÉÓÃʲô½á¹¹¡¢Ê¹ÓÃʲôÓï¾äÒÔ¼°ÈçºÎ°²ÅÅÕâЩÓï¾äµÈ¡£Í¨³£Ê¹ÓÃ×ÔÈ»ÓïÑÔ¡¢½á¹¹»¯Á÷³Ìͼ¡¢Î±´úÂëµÈÀ´ÃèÊöËã·¨¡£
¡¡¡¡Ò»¡¢¼ÆÊý¡¢ÇóºÍ¡ ......