⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 雙色、三色河內塔.mht

📁 23种算法C与JAVA实现 23种算法C与JAVA实现
💻 MHT
📖 第 1 页 / 共 5 页
字号:
From: <由 Microsoft Internet Explorer 5 保存>
Subject: =?gb2312?B?63DJq6GiyP3Jq7rTg8jL/g==?=
Date: Wed, 13 Sep 2006 01:11:57 +0800
MIME-Version: 1.0
Content-Type: multipart/related;
	boundary="----=_NextPart_000_0061_01C6D6D1.9B6AE260";
	type="text/html"
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1807

This is a multi-part message in MIME format.

------=_NextPart_000_0061_01C6D6D1.9B6AE260
Content-Type: text/html;
	charset="big5"
Content-Transfer-Encoding: quoted-printable
Content-Location: http://www.java3z.com/cwbwebhome/article/article3/AlgorithmGossip/MultiColorHanoiTower.htm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>=C2=F9=A6=E2=A1B=A4T=A6=E2=AAe=A4=BA=B6=F0</TITLE>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Dbig5"><LINK=20
href=3D"http://www.java3z.com/cwbwebhome/article/article3/AlgorithmGossip=
/css/stdlayout.css"=20
type=3Dtext/css rel=3Dstylesheet><LINK=20
href=3D"http://www.java3z.com/cwbwebhome/article/article3/AlgorithmGossip=
/css/print.css"=20
type=3Dtext/css rel=3Dstylesheet>
<META content=3D"MSHTML 6.00.2800.1561" name=3DGENERATOR></HEAD>
<BODY>
<H3><A=20
href=3D"http://caterpillar.onlyfun.net/Gossip/index.html">http://caterpil=
lar.onlyfun.net/Gossip/index.html</A></H3>
<H1><A=20
href=3D"http://www.java3z.com/cwbwebhome/article/article3/AlgorithmGossip=
/AlgorithmGossip.htm">Algorithm=20
Gossip:&nbsp;=C2=F9=A6=E2=A1B=A4T=A6=E2=AAe=A4=BA=B6=F0</A></H1>
<H2>=BB=A1=A9=FA</H2>=C2=F9=A6=E2=AAe=A4=BA=B6=F0=BBP=A4T=A6=E2=AAe=A4=BA=
=B6=F0=ACO=A5=D1=A4=A7=ABe=A9=D2=A4=B6=B2=D0=B9L=AA=BA=AAe=A4=BA=B6=F0=B3=
W=ABh=ADl=A5=CD=A6=D3=A8=D3=A1A=C2=F9=A6=E2=AAe=A4=BA=B6=F0=AA=BA=A5=D8=AA=
=BA=ACO=B1N=A4U=B9=CF=A5=AA=A4W=AA=BA=B6=EA=C0=F4=A6=EC=B8m=B8g=B2=BE=B0=CA=
=A6=A8=AC=B0=A5k=A4U=AA=BA=B6=EA=C0=F4=A6=EC=B8m=A1G <BR>
<DIV style=3D"TEXT-ALIGN: center"><IMG =
title=3D=A6h=A6=E2=AAe=A4=BA=B6=F0=20
style=3D"WIDTH: 381px; HEIGHT: 141px" alt=3D=A6h=A6=E2=AAe=A4=BA=B6=F0=20
src=3D"http://www.java3z.com/cwbwebhome/article/article3/AlgorithmGossip/=
images/multiColorHanoiTower-1.jpg"><BR><BR>
<DIV style=3D"TEXT-ALIGN: =
left">=A6=D3=A4T=A6=E2=AAe=A4=BA=B6=F0=ABh=ACO=B1N=A4U=B9=CF=A5=AA=A4W=AA=
=BA=B6=EA=C0=F4=B8g=B2=BE=B0=CA=A6=A8=AC=B0=A5k=A4W=AA=BA=B6=EA=C0=F4=A1G=
 <BR>
<DIV style=3D"TEXT-ALIGN: center"><IMG =
title=3D=A6h=A6=E2=AAe=A4=BA=B6=F0=20
style=3D"WIDTH: 381px; HEIGHT: 141px" alt=3D=A6h=A6=E2=AAe=A4=BA=B6=F0=20
src=3D"http://www.java3z.com/cwbwebhome/article/article3/AlgorithmGossip/=
images/multiColorHanoiTower-2.jpg"><BR></DIV><BR>=A6b=B2=BE=B0=CA=AA=BA=B9=
L=B5{=A4=A4=A1A=A4@=BC=CB=BF=ED=A6u=A4j=BDL=A5=B2=B6=B7=A6b=A4p=BDL=A4=A7=
=A4U=AA=BA=B3W=ABh=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=BDL=A1B=
=A4Q=AD=D3=BDL=A5H=A4W=B5=A5=A1A=B3=A3=ACO=A5=CE=B3o=AD=D3=C6[=A9=C0=A8=D3=
=B8=D1=C3D=A1C<BR><BR>=A8=BA=BB=F2=A4T=A6=E2=AAe=A4=BA=B6=F0=A9O=A1H=A4@=BC=
=CB=A1A=AA=BD=B1=B5=A8=D3=AC=DD=A4E=AD=D3=BDL=AA=BA=B1=A1=AAp=A1A=AD=BA=A5=
=FD=A5=B2=B6=B7=A7=B9=A6=A8=A4U=B9=CF=AA=BA=B2=BE=B0=CA=B5=B2=AAG=A1G<BR>=

<DIV style=3D"TEXT-ALIGN: center"><IMG =
title=3D=A6h=A6=E2=AAe=A4=BA=B6=F0=20
style=3D"WIDTH: 226px; HEIGHT: 63px" alt=3D=A6h=A6=E2=AAe=A4=BA=B6=F0=20
src=3D"http://www.java3z.com/cwbwebhome/article/article3/AlgorithmGossip/=
images/multiColorHanoiTower-5.jpg"><BR></DIV><BR>=B1=B5=A4U=A8=D3=B3=CC=A9=
=B3=A8=E2=BCh=AA=BA=B4N=A4=A3=A5=CE=BA=DE=A5=A6=AD=CC=A4F=A1A=A6]=AC=B0=A5=
=A6=AD=CC=A4w=B8g=B4N=A9w=A6=EC=A1A=A5u=ADn=A6A=B3B=B2z=B2=C4=A4@=ACW=A4W=
=AD=B1=AA=BA=A4T=AD=D3=BDL=A4l=B4N=A5i=A5H=A4F=A1C<BR>
<DIV style=3D"TEXT-ALIGN: center"><IMG =
title=3D=A6h=A6=E2=AAe=A4=BA=B6=F0=20
style=3D"WIDTH: 223px; HEIGHT: 62px" alt=3D=A6h=A6=E2=AAe=A4=BA=B6=F0=20
src=3D"http://www.java3z.com/cwbwebhome/article/article3/AlgorithmGossip/=
images/multiColorHanoiTower-6.jpg"></DIV><BR>=B1z=A4]=A5i=A5H=AC=DD=AC=DD=
=20
<A =
href=3D"http://obelix.ee.duth.gr/~apostolo/TowersOfHanoi/index.html">Towe=
rs of=20
Hanoi Page</A> =
=A4=A4=A6=B3=C3=F6=A9=F3=AAe=A4=BA=B6=F0=AA=BA=B0Q=BD=D7=A1C<BR>
<H2>&nbsp;=B9=EA=A7@</H2>=A5H=A4UJava=BAt=BA=E2=B9=EA=A8=D2=A5=D1 <A=20
href=3D"http://www.javaworld.com.tw/">http://www.javaworld.com.tw/</A> =
=AA=BA <A=20
href=3D"http://www.javaworld.com.tw/jute/user/info?uid=3D3056">T5555</A> =

=B4=A3=A8=D1=A1A=B7P=C1=C2=A5L=AA=BA=A8=F3=A7U=A1A=A7=DA=AE=DA=BE=DA=A5L=AA=
=BA=B9=EA=A8=D2=A1A=C2=E0=B4=AB=AC=B0C=BBy=A8=A5=AA=BA=B9=EA=A7@=B3=A1=A5=
=F7=A1A=B1z=A5i=A5H=B0=D1=A6=D2=B3o=AD=D3 <A=20
href=3D"http://www.javaworld.com.tw/jute/post/view?bid=3D29&amp;id=3D8126=
8&amp;tpg=3D1&amp;ppg=3D1&amp;sty=3D0&amp;age=3D0#81268">=B0Q=BD=D7=A6=EA=
</A>=20
=A6=B3=C3=F6=A9=F3=AAe=A4=BA=B6=F0=AA=BA=B0Q=BD=D7=A1C<BR><BR>
<UL>
  <LI>=C2=F9=A6=E2=AAe=A4=BA=B6=F0 C =B9=EA=A7@ </LI></UL><PRE>#include =
&lt;stdio.h&gt;<BR><BR>void hanoi(int disks, char source, char temp, =
char target) {<BR>    if (disks =3D=3D 1) {<BR>        printf("move disk =
from %c to %c\n", source, target);<BR>        printf("move disk from %c =
to %c\n", source, target);<BR>    } else {<BR>        hanoi(disks-1, =
source, target, temp);<BR>        hanoi(1, source, temp, target);<BR>    =
    hanoi(disks-1, temp, source, target);<BR>    }<BR>}<BR><BR>void =
hanoi2colors(int disks) {<BR>    char source =3D 'A';<BR>    char temp =
=3D 'B';<BR>    char target =3D 'C';<BR>    int i;<BR>    for(i =3D =
disks / 2; i &gt; 1; i--) {<BR>        hanoi(i-1, source, temp, =
target);<BR>        printf("move disk from %c to %c\n", source, =
temp);<BR>        printf("move disk from %c to %c\n", source, temp);<BR> =
       hanoi(i-1, target, temp, source);<BR>        printf("move disk =
from %c to %c\n", temp, target);<BR>    }<BR>    printf("move disk from =
%c to %c\n", source, temp);<BR>    printf("move disk from %c to %c\n", =
source, target);<BR>}<BR><BR>int main() {<BR>    int n;<BR>    =
printf("=BD=D0=BF=E9=A4J=BDL=BC=C6=A1G");<BR>    scanf("%d", =
&amp;n);<BR><BR>    hanoi2colors(n);<BR><BR>    return 0;<BR>} =
<BR></PRE><BR>
<UL>
  <LI>=A4T=A6=E2=AAe=A4=BA=B6=F0 C =B9=EA=A7@ </LI></UL><PRE>#include =
&lt;stdio.h&gt;<BR><BR>void hanoi(int disks, char source, char temp, =
char target) {<BR>    if (disks =3D=3D 1) {<BR>        printf("move disk =
from %c to %c\n", source, target);<BR>        printf("move disk from %c =
to %c\n", source, target);<BR>        printf("move disk from %c to =
%c\n", source, target);<BR>    } else {<BR>        hanoi(disks-1, =
source, target, temp);<BR>        hanoi(1, source, temp, target);<BR>    =
    hanoi(disks-1, temp, source, target);<BR>    }<BR>}<BR><BR>void =
hanoi3colors(int disks) {<BR>    char source =3D 'A';<BR>    char temp =
=3D 'B';<BR>    char target =3D 'C';<BR>    int i;<BR><BR>    if(disks =
=3D=3D 3) {<BR>        printf("move disk from %c to %c\n", source, =
temp);<BR>        printf("move disk from %c to %c\n", source, temp);<BR> =
       printf("move disk from %c to %c\n", source, target);<BR>        =
printf("move disk from %c to %c\n", temp, target);<BR>        =
printf("move disk from %c to %c\n", temp, source);<BR>        =
printf("move disk from %c to %c\n", target, temp);;<BR>    }<BR>    else =
{<BR>        hanoi(disks/3-1, source, temp, target);<BR>        =
printf("move disk from %c to %c\n", source, temp);<BR>        =
printf("move disk from %c to %c\n", source, temp);<BR>        =
printf("move disk from %c to %c\n", source, temp);<BR><BR>        =
hanoi(disks/3-1, target, temp, source);<BR>        printf("move disk =
from %c to %c\n", temp, target);<BR>        printf("move disk from %c to =
%c\n", temp, target);<BR>        printf("move disk from %c to %c\n", =
temp, target);<BR><BR>        hanoi(disks/3-1, source, target, =
temp);<BR>        printf("move disk from %c to %c\n", target, =
source);<BR>        printf("move disk from %c to %c\n", target, =
source);<BR><BR>        hanoi(disks/3-1, temp, source, target);<BR>      =
  printf("move disk from %c to %c\n", source, temp);<BR>        <BR>     =
   for (i =3D disks / 3 - 1; i &gt; 0; i--) {<BR>            if (i&gt;1) =
{<BR>                hanoi(i-1, target, source, temp);<BR>            =
}<BR><BR>            printf("move disk from %c to %c\n",<BR>             =
                    target, source);<BR>            printf("move disk =
from %c to %c\n",<BR>                                 target, =
source);<BR><BR>            if (i&gt;1) {<BR>                hanoi(i-1, =
temp, source, target);<BR>            }<BR>            printf("move disk =
from %c to %c\n", <BR>                                   source, =
temp);<BR>        }<BR>    }<BR>}<BR><BR>int main() {<BR>    int n;<BR>  =
  printf("=BD=D0=BF=E9=A4J=BDL=BC=C6=A1G");<BR>    scanf("%d", =
&amp;n);<BR><BR>    hanoi3colors(n);<BR><BR>    return 0;<BR>} =
<BR></PRE><BR>
<UL>
  <LI>=C2=F9=A6=E2=AAe=A4=BA=B6=F0 Java =B9=EA=A7@ </LI></UL><PRE>public =
class Hanoi2Colors { <BR>    public static void help() {<BR>        =
System.out.println(<BR>              "Usage: java Hanoi2Colors =
number_of_disks");<BR>        System.out.println(<BR>              "\t =
number_of_disks: must be a even number.");<BR>        =
System.exit(0);<BR>    }<BR>    <BR>    public static void main(String[] =
args) {<BR>        int disks =3D 0;        <BR>        try {<BR>         =
   disks =3D Integer.parseInt(args[0]);<BR>        } catch (Exception e) =
{<BR>            help();<BR>        }<BR>        if ((disks &lt;=3D 0) =
|| (disks % 2 !=3D 0)) { <BR>            help(); <BR>        }<BR>       =
 hanoi2colors(disks);<BR>    }<BR>     <BR>    public static void =
hanoi(int disks, <BR>                      char source, char temp, char =
target) {<BR>        if (disks =3D=3D 1) {<BR>            =
System.out.println("move disk from " <BR>                               =

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -