經(jīng)典遞歸小程序--漢諾塔

#include <stdio.h>

創(chuàng)新互聯(lián)公司是一家專注于做網(wǎng)站、網(wǎng)站設(shè)計(jì)與策劃設(shè)計(jì),奎屯網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)公司做網(wǎng)站,專注于網(wǎng)站建設(shè)十多年,網(wǎng)設(shè)計(jì)領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:奎屯等地區(qū)??妥鼍W(wǎng)站價(jià)格咨詢:028-86922220

/*

思路:1、將1到n-1號盤子借助C移到B上

 2、將n號盤子移到C上

 3、將1到n-1號盤子借助A移到C上

  */

//初始化步數(shù)

int i = 0;

void move(int,char,char);

void hannuota(int,char,char,char);

void main(void){

int n;

printf("請輸入漢諾塔盤子的個(gè)數(shù):");

scanf("%d",&n);

hannuota(n,'A','C','B');

}

//移動盤子方法

void move(int n,char from,char to){

printf("第%d步,將%d號盤子從%c移到%c\n",++i,n,from,to);

}

//漢諾塔遞歸算法

void hannuota(int n,char from,char to,char depend_on){

if(n == 1){

move(1,from,to);

}else{

hannuota(n-1,from,depend_on,to);

move(n,from,to);

hannuota(n-1,depend_on,to,from);

}

}

網(wǎng)站名稱:經(jīng)典遞歸小程序--漢諾塔
分享路徑:http://bm7419.com/article14/jcejde.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制網(wǎng)站、小程序開發(fā)、外貿(mào)建站、微信公眾號、品牌網(wǎng)站建設(shè)、自適應(yīng)網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

小程序開發(fā)