?? hanio.cpp
字號:
/*#include<iostream.h>
#define maxlen 50
void hano(int n,char a,char b,char c)
{
if(n==1)
cout<<"將第"<<n<<"個圓盤從"<<a<<"移到"<<c<<endl;
else
{ hano(n-1,a,c,b);
cout<<"將第"<<n<<"個圓盤從"<<a<<"移到"<<c<<endl;
hano(n-1,b,a,c);
}
}
void hanota(int n,char a,char b,char c)
{
struct stack
{int no,ns;
char x,y,z;
};
stack st[maxlen];
int top=1;
int n1,a1,b1,c1;
st[top].no=1;
st[top].ns=n;
st[top].x=a;
st[top].y=b;
st[top].z=c;//
while(top>0)
{ if(st[top].no==1)
{
n1=st[top].ns;
a1=st[top].x;
b1=st[top].y;
c1=st[top].z;
//top--;
//top++;
st[top].no=1;
st[top].ns=n1-1;
st[top].x=b1;
st[top].y=a1;
st[top].z=c1;
top++;
st[top].no=0;
st[top].ns=n1;
st[top].x=a1;
st[top].y=c1;
top++;
st[top].no=1;
st[top].ns=n1-1;
st[top].x=a1;
st[top].y=c1;
st[top].z=b1;
}
while(top>0&&(st[top].no==0||st[top].ns==1))
{
if(top>0&&st[top].no==0)
{
cout<<"將第"<<st[top].ns<<"個圓盤從"<<st[top].x<<"移到"<<st[top].y<<endl;
top--;
}
if(top>0&&st[top].ns==1)
{
cout<<"將第"<<st[top].ns<<"個圓盤從"<<st[top].x<<"移到"<<st[top].z<<endl;
top--;
}
}
}
}
void main()
{
int n;
cout<<"please enter the order of hanoi"<<endl;
cin>>n;
hano(n,'A','B','C');
cout<<"the same answer"<<endl;
hanota(n,'A','B','C');
}
*/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -