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

📄 约瑟夫环_数据结构与算法_数据结构算法_c语言_c 语言之家.htm

📁 严蔚民版的数据结构的完整课件
💻 HTM
📖 第 1 页 / 共 3 页
字号:
            href="http://www.cstudyhome.com/wenzhang06/">网站首页</A>&gt;&gt;<A 
            class=class 
            href="http://www.cstudyhome.com/wenzhang06/type.asp?typeid=11">C语言</A>&gt;&gt;<A 
            class=class 
            href="http://www.cstudyhome.com/wenzhang06/BigClass.asp?typeid=11&amp;BigClassid=33">数据结构算法</A>&gt;&gt;<A 
            class=class 
            href="http://www.cstudyhome.com/wenzhang06/SmallClass.asp?typeid=11&amp;BigClassID=33&amp;SmallClassID=60">数据结构与算法</A></TD>
          <TD background="约瑟夫环_数据结构与算法_数据结构算法_C语言_C 语言之家.files/banbg.gif" 
          height=20 width=107>双击自动滚屏</TD>
          <TD background="约瑟夫环_数据结构与算法_数据结构算法_C语言_C 语言之家.files/banbg.gif" 
          width=91><INPUT name=close onclick="window.close();return false;" type=button value=关闭窗口> 
          </TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
<TABLE align=center border=3 borderColor=#e2ca9f cellPadding=0 cellSpacing=0 
style="BORDER-COLLAPSE: collapse" width=750>
  <TBODY>
  <TR><!--<td width="20%" align="middle" valign="top" background="images/002.jpg" bordercolor="#e2ca9f"> </td> 
<td width="80%">-->
    <TD width="100%">
      <TABLE border=0 borderColor=#e2ca9f cellPadding=0 cellSpacing=0 
      width="100%">
        <TBODY>
        <TR>
          <TD align=middle vAlign=top width="95%">
            <TABLE border=1 borderColor=#e2ca9f cellPadding=0 cellSpacing=0 
            width="100%">
              <TBODY>
              <TR>
                <TD align=middle 
                background="约瑟夫环_数据结构与算法_数据结构算法_C语言_C 语言之家.files/002.jpg" 
                borderColor=#e2ca9f vAlign=top width="69%">
                  <TABLE align=center border=0 cellPadding=0 cellSpacing=0 
                  width="100%">
                    <TBODY>
                    <TR>
                      <TD height=40 width="100%"></TD></TR>
                    <TR>
                      <TD>
                        <FORM action=Readnews.asp?newsid=3551&amp;id2=3551 
                        method=post name=form1>
                        <CENTER><!-- <input type=submit name=aa value="点击关闭浮动图标" width=20 title="点击广告支持本站">--></CENTER></FORM></TD></TR>
                    <TR>
                      <TD align=middle bgColor=#dddddd height=20 
                      style="FONT-SIZE: 18px" vAlign=bottom 
                        width="85%"><STRONG><FONT color=#003399 size=4><B>约瑟夫环 
                        </B></FONT></STRONG></TD><BR></TR>
                    <TR>
                      <TD align=middle width="100%"><BR></TD></TR>
                    <TR>
                      <TD align=middle style="FONT-SIZE: 9pt" 
                        width="100%">发表日期:2004年5月24日&nbsp;&nbsp;出处:我的数据结构实验报告&nbsp;&nbsp;作者:刘志宽&nbsp;&nbsp;已经有2680位读者读过此文</TD></TR>
                    <TR>
                      <TD align=middle width="100%"><!--下面的这一句是设置阅读文本区的宽度-->
                        <TABLE align=center border=0 cellPadding=0 cellSpacing=0 
                        style="TABLE-LAYOUT: fixed" width="90%">
                          <TBODY>
                          <TR>
                            <TD align=middle width="100%"></TD></TR>
                          <TR>
                            <TD style="WORD-WRAP: break-word"><FONT 
                              class=news><BR>
                              <P>约瑟夫环问题描述:标号为1,2,...,n的n个人按顺时针方向围坐一圈,每人持有一个密码(正整数)。一开始任选</P>
                              <P>一个整数作为报数上限值m,从第一个人开始按顺时针方向自1开始顺序报数,报到m时停止报数。报m的人出列,将他的</P>
                              <P>密码作为新的m值,从他在顺时针方向上的下一个人开始重新从1报数,如此下去,直至所有人全部出列为止。试设计一</P>
                              <P>个程序求出出列顺序。</P>
                              <P>作者按:本人的程序勉强能达到标准,但是容错性比较差,如果对于用户的任何输入都能作出反映就更好了。即当</P>
                              <P>用户输入不合理的字符或数字时,能够显示出错信息,提醒重新输入。希望得到众位高手的指教!!</P>
                              <P>附录:测试数据m出值为20,n=7,7个人密码依次是:3,1,7,2,4,8,4。</P>
                              <P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                              正确的出列顺序是6,1,4,7,2,3,5。</P>
                              <P>&nbsp;</P>
                              <P>#define NULL 0<BR>#define LEN sizeof(struct 
                              Joseph)<BR>struct Joseph<BR>{int num;<BR>&nbsp;int 
                              secret;<BR>&nbsp;struct Joseph *next;<BR>};</P>
                              <P>struct Joseph *creat()<BR>{struct Joseph 
                              *head;<BR>&nbsp;struct Joseph 
                              *p1,*p2;<BR>&nbsp;int n=0;<BR>&nbsp;p1=p2=(struct 
                              Joseph 
                              *)malloc(LEN);<BR>&nbsp;scanf("%d,%d",&amp;p1-&gt;num,&amp;p1-&gt;secret);<BR>&nbsp;head=NULL;</P>
                              <P>&nbsp;while(p1-&gt;num!=0)<BR>&nbsp;&nbsp; 
                              {n=n+1;<BR>&nbsp;&nbsp;&nbsp; 
                              if(n==1)head=p1;<BR>&nbsp;&nbsp;&nbsp; else 
                              p2-&gt;next=p1;<BR>&nbsp;&nbsp;&nbsp; 
                              p2=p1;<BR>&nbsp;&nbsp;&nbsp; p1=(struct Joseph 
                              *)malloc(LEN);<BR>&nbsp;&nbsp;&nbsp; 
                              scanf("%d,%d",&amp;p1-&gt;num,&amp;p1-&gt;secret);<BR>&nbsp;&nbsp;&nbsp; 
                              }<BR>&nbsp;p2-&gt;next=head;<BR>&nbsp;return(head);<BR>&nbsp;}</P>
                              <P>&nbsp;sort(head,m)<BR>&nbsp;struct Joseph 
                              *head;<BR>&nbsp;int m;<BR>&nbsp;{struct Joseph 
                              *p1,*p2;<BR>&nbsp;&nbsp; int i;<BR>&nbsp;&nbsp; 
                              if(head==NULL)<BR>&nbsp;&nbsp;&nbsp;&nbsp; 
                              printf("\nlist null!\n");<BR>&nbsp;&nbsp; 
                              p1=head;</P>
                              <P>&nbsp;&nbsp; 
                              while(p1-&gt;next!=p1)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                              {for(i=1;i&lt;m;i++)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                              {p2=p1;p1=p1-&gt;next;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                              p2-&gt;next=p1-&gt;next;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                              m=p1-&gt;secret;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                              printf("%d&nbsp; 
                              ",p1-&gt;num);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                              p1=p2-&gt;next;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                              }<BR>&nbsp;&nbsp; 
                              if(p1-&gt;next==p1)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                              printf("%d ",p1-&gt;num);<BR>&nbsp; }</P>
                              <P><BR>main()<BR>{struct Joseph 
                              *head;<BR>&nbsp;int m;<BR>&nbsp;printf("\ninput 
                              records:the format is number,password.\nand please 
                              end with 
                              0,0\n");<BR>&nbsp;head=creat();<BR>&nbsp;printf("input 
                              m\n");<BR>&nbsp;scanf("%d",&amp;m);<BR>&nbsp;if(m&lt;1)printf("error! 
                              please input a legal m!");<BR>&nbsp;printf("the 
                              sorted num 
                              is:\n");<BR>&nbsp;sort(head,m);<BR>}</P>
                              <P>&nbsp;</P><BR></FONT></TD></TR></TBODY></TABLE></TD></TR>
                    <TR>
                      <TD height=25 width="100%">
                        <DIV align=center></DIV></TD></TR>
                    <TR>
                      <TD height=20 width=255><A class=bottom 
                        href="http://www.cstudyhome.com/wenzhang06/review.asp?NewsID=3551" 
                        target=_blank>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<IMG 
                        border=0 height=18 
                        src="约瑟夫环_数据结构与算法_数据结构算法_C语言_C 语言之家.files/icon1.gif" 
                        width=18> <FONT color=blue>发表评论</FONT></A> </TD></TR>
                    <TR>
                      <TD width="100%">
                        <HR SIZE=1>
                      </TD></TR>
                    <TR>
                      <TD height=8></TD></TR>
                    <TR>
                      <TD height=18 width="100%"><B>相关专题:</B> 
                    <TR>
                      <TD width="100%">
                        <HR SIZE=1>
                      </TD></TR>
                    <TR>
                      <TD height=8></TD></TR>
                    <TR>
                      <TD height=18 width="100%"><B>相关信息:</B></TD></TR>
                    <TR>
                      <TD height=8></TD></TR>
                    <TR>
                      <TD width="100%">&nbsp;没有相关信息</TD></TR>
                    <TR>
                      <TD width="100%">
                        <HR SIZE=1>
                      </TD></TR>
                    <TR>
                      <TD height=8></TD></TR>
                    <TR>
                      <TD width="100%"><B>相关评论:</B></TD></TR>
                    <TR>
                      <TD height=8></TD></TR>
                    <TR>
                      <TD width="100%"></TD></TR>
                    <TR>
                      <TD>
                        <TABLE border=0 cellPadding=5 cellSpacing=0 
width="100%">
                          <TBODY>
                          <TR bgColor=#d1e4fc>
                            <TD 
                              width="100%">发表人:→戀氺Δē魚&nbsp;&nbsp;&nbsp;发表人邮件:<A 
                              href="mailto:xujianfeng130@tom.com">xujianfeng130@tom.com</A>&nbsp;&nbsp;&nbsp;发表时间:2004-5-31 
                              15:11:37</TD>
                            <TD width=270>
                              <P align=right></P></TD></TR>

⌨️ 快捷键说明

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