herrDeng網內搜尋

自訂搜尋

Ads

2018年1月2日 星期二

ex12 用遞迴撰寫hanoi tower河內塔

29 則留言:

B10633105 劉晉良 提到...

#include <iostream>

void hanoiTower(int n, char x, char y, char z);


void hanoiTower(int n, char x, char y, char z) {

if (n == 1) {
std::cout << "Disk" << 1 << "from" << x << "to" << z'\n';
} else {
hanoiTower(n-1, x, y, z);
std::cout << "Disk" << 1 << " from" << x << "to" << z'\n';
hanoiTower(n-1, x, y, z);
}
}
int main(int argc, char** argv) {
hanoiTower(5, 'a', 'b', 'c');
return 0;
}

b10633091 楊子安 提到...

#include <iostream>

void hanoiTower(int n, char x, char y, char z);


void hanoiTower(int n, char x, char y, char z) {

if (n == 1) {
std::cout << "Disk" << 1 << "from" << x << "to" << z'\n';
} else {
hanoiTower(n-1, x, y, z);
std::cout << "Disk" << 1 << " from" << x << "to" << z'\n';
hanoiTower(n-1, x, y, z);
}
}
int main(int argc, char** argv) {
hanoiTower(5, 'a', 'b', 'c');
return 0;
}

B10633104 王湘柔 提到...

#include <iostream>

void hanoiTower(int n, char x, char y, char z);


void hanoiTower(int n, char x, char y, char z) {

if (n == 1) {
std::cout << "Disk" << 1 << "from" << x << "to" << z'\n';
} else {
hanoiTower(n-1, x, y, z);
std::cout << "Disk" << 1 << " from" << x << "to" << z'\n';
hanoiTower(n-1, x, y, z);
}
}
int main(int argc, char** argv) {
hanoiTower(5, 'a', 'b', 'c');
return 0;
}

b10633070 陳鴻琪 提到...

#include <iostream>

void hanoiTower(int n, char x, char y, char z);


void hanoiTower(int n, char x, char y, char z) {

if (n == 1) {
std::cout << "Disk" << 1 << "from" << x << "to" << z'\n';
} else {
hanoiTower(n-1, x, y, z);
std::cout << "Disk" << 1 << " from" << x << "to" << z'\n';
hanoiTower(n-1, x, y, z);
}
}
int main(int argc, char** argv) {
hanoiTower(5, 'a', 'b', 'c');
return 0;
}

A10633020 陳俐婷 提到...

#include <iostream>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

void hanoiTower(int n, char x, char y, char z){
if(n == 1){
std::cout << "Disk " << 1 << " from " << x << " to " << z <<'\n';
}else{
hanoiTower(n-1,x,y,z);
std::cout << "Disk " << n << " from " << x << " to " << z <<'\n';
hanoiTower(n-1,y,x,z);
}
}

int main(int argc, char** argv) {
hanoiTower(5,'a','b','c');
return 0;
}

A10633022 黃皓銘 提到...

#include <iostream>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
void hanoiTower(int n, char x, char y, char z){

if(n ==1){
std::cout << "Disk " << 1 << " from " << x << " to " << z <<'\n';
}else{
hanoiTower(n-1, y, x, z);
std::cout << "Disk " << n << " from " << x << " to " << z <<'\n';
hanoiTower(n-1, y, x, z);
}
}

int main(int argc, char** argv) {
hanoiTower(5, 'a', 'b', 'c');
return 0;
}

A10633011 邱軍霖 提到...

#include <iostream>
using namespace std;
void move(int n, char a, char b){
cout<<"Disc"<<n<<"從"<<a<<"到"<<b<<endl;
}
void hanoiTower(int n, char from_peg, char peg3, char to_peg)
{
if(n==1) move(n, from_peg, to_peg);
else{
hanoiTower(n-1, from_peg, to_peg, peg3);
move(n, from_peg, to_peg);
hanoiTower(n-1, peg3, from_peg, to_peg);

}
}
int main()
{
hanoiTower(5, 'a', 'b', 'c');
return 0;
}

B10633073 吳聲佑 提到...

#include <iostream>

void hanoiTower(int n, char x, char y, char z);


void hanoiTower(int n, char x, char y, char z) {

if (n == 1) {
std::cout << "Disk" << 1 << "from" << x << "to" << z'\n';
} else {
hanoiTower(n-1, x, y, z);
std::cout << "Disk" << 1 << " from" << x << "to" << z'\n';
hanoiTower(n-1, x, y, z);
}
}
int main(int argc, char** argv) {
hanoiTower(5, 'a', 'b', 'c');
return 0;
}

b10624024 提到...

#include <iostream>

using namespace std;
void move(int n,char a,char b){
cout<<"disc"<<n<<"從"<<a<<"到"<<b<<endl;
}
void hanoitower(int n,char from_peg,char peg3,char to_peg)
{
if(n==1) move(n, from_peg , to_peg);
else{
hanoitower(n-1, from_peg , to_peg , peg3);
move(n, from_peg , to_peg );
hanoitower(n-1 , peg3, from_peg , to_peg);
}
}

int main()
{
hanoitower(5,'a','b','c');
return 0;
}

A10633016張貴棠 提到...

#include <iostream>
using namespace std;
void move (int n, char a, char b){
cout<<"Disc"<<n<<" 從"<<a<<"到"<<b<<endl;
}
void hanoiTower(int n, char from_peg, char peg3, char to_peg)
{
if(n==1) move(n, from_peg, to_peg);
else{
hanoiTower(n-1,from_peg, to_peg,peg3);
move(n, from_peg, to_peg);
hanoiTower(n-1,peg3, from_peg, to_peg);
}
}
int main()
{
hanoiTower(5, 'a','b','c');
return 0;
}

b10633080黃主賜 提到...

#include <iostream>

void hanoiTower(int n, char x, char y, char z);


void hanoiTower(int n, char x, char y, char z) {

if (n == 1) {
std::cout << "Disk" << 1 << "from" << x << "to" << z'\n';
} else {
hanoiTower(n-1, x, y, z);
std::cout << "Disk" << 1 << " from" << x << "to" << z'\n';
hanoiTower(n-1, x, y, z);
}
}
int main(int argc, char** argv) {
hanoiTower(5, 'a', 'b', 'c');
return 0;
}

b10633076謝昀憲 提到...

#include <iostream>

void hanoiTower(int n, char x, char y, char z);


void hanoiTower(int n, char x, char y, char z) {

if (n == 1) {
std::cout << "Disk" << 1 << "from" << x << "to" << z'\n';
} else {
hanoiTower(n-1, x, y, z);
std::cout << "Disk" << 1 << " from" << x << "to" << z'\n';
hanoiTower(n-1, x, y, z);
}
}
int main(int argc, char** argv) {
hanoiTower(5, 'a', 'b', 'c');
return 0;
}

B10633081 陳蕙祺 提到...

#include <iostream>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
void hanoiToewr(int n, char x, char y, char z) {

if ( n == 1) {
std::cout << "Disk "<< 1 << "form " << x << " to " << z <<'\n';
} else {
hanoiToewr(n-1, x, z, y);
std::cout << "Disk "<< 1 << "form " << x << " to " << z <<'\n';
hanoiToewr(n-1, x, z, y);
}
}
int main(int argc, char** argv) {
hanoiToewr(5, 'a','b','c');
return 0;
}

b10633159 徐芳瑀 提到...

#include <iostream>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
void hanoiTower(int n, char x, char y, char z) {

if (n == 1) {
std ::cout << "Disk " << 1 << " from " << x << " to " << z <<'\n';
} else {
hanoiTower(n-1, x, z, y);
std ::cout << "Disk " << 1 << " from " << x << " to " << z <<'\n';
hanoiTower(n-1, x, z, y);
}
}
int main(int argc, char** argv) {
hanoiTower(5, 'a', 'b', 'c');
return 0;
}

B10633100 陳澔翰 提到...

#include <iostream>

void hanoiTower(int n, char x, char y, char z);


void hanoiTower(int n, char x, char y, char z) {

if (n == 1) {
std::cout << "Disk" << 1 << "from" << x << "to" << z'\n';
} else {
hanoiTower(n-1, x, y, z);
std::cout << "Disk" << 1 << " from" << x << "to" << z'\n';
hanoiTower(n-1, x, y, z);
}
}
int main(int argc, char** argv) {
hanoiTower(5, 'a', 'b', 'c');
return 0;
}

B10633086鄭羽伸 提到...

#include <iostream>

void hanoiTower(int n, char x, char y, char z);


void hanoiTower(int n, char x, char y, char z) {

if (n == 1) {
std::cout << "Disk" << 1 << "from" << x << "to" << z'\n';
} else {
hanoiTower(n-1, x, y, z);
std::cout << "Disk" << 1 << " from" << x << "to" << z'\n';
hanoiTower(n-1, x, y, z);
}
}
int main(int argc, char** argv) {
hanoiTower(5, 'a', 'b', 'c');
return 0;
}

B10533083徐士興 提到...

#include <iostream>


void hanoitower(int n, char x, char y, char z ) {

if (n == 1) {
std::cout << "Disk " << 1 << " from " << x << " to "<< z <<'\n';
} else {
hanoiTower(n-1, x, z, y);
std::cout << "Disk" << n << " from " << x << " to " << z<<'\n';
hanoiTower(n-1, y, x, z);
}
}
int main(int argc, char** argv) {
hanoiTower(5, 'a', 'b', 'c');
return 0;
}

B10533088葉俊江 提到...

#include <iostream>


void hanoitower(int n, char x, char y, char z ) {

if (n == 1) {
std::cout << "Disk " << 1 << " from " << x << " to "<< z <<'\n';
} else {
hanoiTower(n-1, x, z, y);
std::cout << "Disk" << n << " from " << x << " to " << z<<'\n';
hanoiTower(n-1, y, x, z);
}
}
int main(int argc, char** argv) {
hanoiTower(5, 'a', 'b', 'c');
return 0;
}

B10433015周采萱 提到...

using namespace std;
void move(int n, char a, char b){
cout<<"Disk "<<n<<" from "<<a<<" to "<<b<<endl;
}
void hanoiTower(int n, char from_peg, char peg3, char to_peg)
{
if(n==1) move(n, from_peg, to_peg);
else{
hanoiTower(n-1, from_peg, to_peg, peg3);
move(n, from_peg, to_peg);
hanoiTower(n-1, peg3, from_peg, to_peg);
}
}
int main() {
hanoiTower(5,'a','b','c');
return 0;
}

B10633064 徐敏嫣 提到...

void hanoiTower(int n, cher x, cher y, cher z) {

if (n == 1){
std::count << "Disk " << 1 << " from " << x << " to " << z <<'\n';
} else {
hanoiTower(n-1, x, z, y);
std::count << "Disk " << n << " from " << x << " to " << z <<'\n';
hanoiTower(n-1, y, x, z);
}
}
int main(int argc, char** argv) {
hanoiTower(5, 'a', 'b', 'c');
return 0;
}

B10633082 張瑋芹 提到...

void hanoiTower(int n, cher x, cher y, cher z) {

if (n == 1){
std::count << "Disk " << 1 << " from " << x << " to " << z <<'\n';
} else {
hanoiTower(n-1, x, z, y);
std::count << "Disk " << n << " from " << x << " to " << z <<'\n';
hanoiTower(n-1, y, x, z);
}
}
int main(int argc, char** argv) {
hanoiTower(5, 'a', 'b', 'c');
return 0;
}

B10633079 劉佩儒 提到...

void hanoiTower(int n, cher x, cher y, cher z) {

if (n == 1){
std::count << "Disk " << 1 << " from " << x << " to " << z <<'\n';
} else {
hanoiTower(n-1, x, z, y);
std::count << "Disk " << n << " from " << x << " to " << z <<'\n';
hanoiTower(n-1, y, x, z);
}
}
int main(int argc, char** argv) {
hanoiTower(5, 'a', 'b', 'c');
return 0;
}

B10537208楊蕊筑 提到...

#include
using namespace std;
void move (int n, char a, char b){
cout<<"Disc"<<n<<" 從"<<a<<"到"<<b<<endl;
}
void hanoiTower(int n, char from_peg, char peg3, char to_peg)
{
if(n==1) move(n, from_peg, to_peg);
else{
hanoiTower(n-1,from_peg, to_peg,peg3);
move(n, from_peg, to_peg);
hanoiTower(n-1,peg3, from_peg, to_peg);
}
}
int main()
{
hanoiTower(5, 'a','b','c');
return 0;
}

b10533085羅偉辰 提到...

#include

void hanoiTower(int n, char x, char y, char z);


void hanoiTower(int n, char x, char y, char z) {

if (n == 1) {
std::cout << "Disk" << 1 << "from" << x << "to" << z'\n';
} else {
hanoiTower(n-1, x, y, z);
std::cout << "Disk" << 1 << " from" << x << "to" << z'\n';
hanoiTower(n-1, x, y, z);
}
}
int main(int argc, char** argv) {
hanoiTower(5, 'a', 'b', 'c');
return 0;
}

b10433088葉凱文 提到...

#include

void hanoiTower(int n, char x, char y, char z);


void hanoiTower(int n, char x, char y, char z) {

if (n == 1) {
std::cout << "Disk" << 1 << "from" << x << "to" << z'\n';
} else {
hanoiTower(n-1, x, y, z);
std::cout << "Disk" << 1 << " from" << x << "to" << z'\n';
hanoiTower(n-1, x, y, z);
}
}
int main(int argc, char** argv) {
hanoiTower(5, 'a', 'b', 'c');
return 0;
}

b10533063陳廣制 提到...

#include
using namespace std;
void move (int n, char a, char b){
cout<<"Disc"<<n<<" 從"<<a<<"到"<<b<<endl;
}
void hanoiTower(int n, char from_peg, char peg3, char to_peg)
{
if(n==1) move(n, from_peg, to_peg);
else{
hanoiTower(n-1,from_peg, to_peg,peg3);
move(n, from_peg, to_peg);
hanoiTower(n-1,peg3, from_peg, to_peg);
}
}
int main()
{
hanoiTower(5, 'a','b','c');
return 0;
}

b10533063陳廣制 提到...

#include
using namespace std;
void move (int n, char a, char b){
cout<<"Disc"<<n<<" 從"<<a<<"到"<<b<<endl;
}
void hanoiTower(int n, char from_peg, char peg3, char to_peg)
{
if(n==1) move(n, from_peg, to_peg);
else{
hanoiTower(n-1,from_peg, to_peg,peg3);
move(n, from_peg, to_peg);
hanoiTower(n-1,peg3, from_peg, to_peg);
}
}
int main()
{
hanoiTower(5, 'a','b','c');
return 0;
}

b10533063陳廣制 提到...

#include

void hanoiTower(int n, char x, char y, char z);


void hanoiTower(int n, char x, char y, char z) {

if (n == 1) {
std::cout << "Disk" << 1 << "from" << x << "to" << z'\n';
} else {
hanoiTower(n-1, x, y, z);
std::cout << "Disk" << 1 << " from" << x << "to" << z'\n';
hanoiTower(n-1, x, y, z);
}
}
int main(int argc, char** argv) {
hanoiTower(5, 'a', 'b', 'c');
return 0;
}

b10533063陳廣制 提到...

#include

void hanoiTower(int n, char x, char y, char z);


void hanoiTower(int n, char x, char y, char z) {

if (n == 1) {
std::cout << "Disk" << 1 << "from" << x << "to" << z'\n';
} else {
hanoiTower(n-1, x, y, z);
std::cout << "Disk" << 1 << " from" << x << "to" << z'\n';
hanoiTower(n-1, x, y, z);
}
}
int main(int argc, char** argv) {
hanoiTower(5, 'a', 'b', 'c');
return 0;
}

Related Posts Plugin for WordPress, Blogger...

熱門文章