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

📄 subject_26759.htm

📁 一些关于vc的问答
💻 HTM
字号:
<p>
序号:26759 发表者:heavenkiller 发表日期:2003-01-04 20:44:10
<br>主题:救命啊!MY GOD!
<br>内容://这是一个表的维护的问题,在一个按从小到大的顺序排列的数组中,插入一个数OTHER<BR>//程序将这个数与数组中的数比较之后,将它按从小到大的顺序插入数组中<BR>#include &lt;iostream.h&gt;<BR>const int MAX=100;<BR>int queen(int [],int,int);<BR><BR>//relization of function<BR><BR>int queen(int vol[],int n,int another)<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;int i=0,k;<BR>&nbsp;&nbsp;&nbsp;&nbsp;while (another&gt;vol[i])<BR>&nbsp;&nbsp;&nbsp;&nbsp;{i++;}<BR><BR>&nbsp;&nbsp; for (k=n;k=i;k--)<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vol[k]=vol[k-1];<BR>&nbsp;&nbsp; }<BR>&nbsp;&nbsp; vol[k]=another;<BR>&nbsp;&nbsp; cout &lt;&lt;"notice:";<BR>&nbsp;&nbsp; cout &lt;&lt;vol[k]&lt;&lt;endl;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return (n+1);<BR>}<BR><BR>main ()<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;int num[MAX]={109,122,136,144,157,172,178,185,192,9999};<BR>&nbsp;&nbsp;&nbsp;&nbsp;int m=10,other,i,n,z;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;cout &lt;&lt;"*********************************************"&lt;&lt;endl;<BR>&nbsp;&nbsp;&nbsp;&nbsp;cout &lt;&lt;"the first:"&lt;&lt;num[0]&lt;&lt;endl;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;for (i=0;i&lt;m;i++)<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout &lt;&lt;num[i]&lt;&lt;endl;<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR><BR><BR><BR><BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;cout &lt;&lt;"please enter the number you want to insert:";<BR>&nbsp;&nbsp;&nbsp;&nbsp;cin &gt;&gt;other;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;n=queen(num,m,other);<BR><BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;cout &lt;&lt;"*********************************************"&lt;&lt;endl;<BR>&nbsp;&nbsp;&nbsp;&nbsp;cout &lt;&lt;"the first:"&lt;&lt;num[0]&lt;&lt;endl;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;for (i=0;i&lt;m;i++)<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout &lt;&lt;num[i]&lt;&lt;endl;<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;cout &lt;&lt;n&lt;&lt;endl;<BR>&nbsp;&nbsp;&nbsp;&nbsp;cin &gt;&gt;z;<BR>&nbsp;&nbsp;&nbsp;&nbsp;return 0;<BR>}<BR><BR><BR>但是我在运行这个程序的时候系统出现崩溃,我查了半天也不知是为什么,只有把它发到网上求助各位了!<BR>
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:tjhe 回复日期:2003-01-04 21:08:29
<br>内容:int queen(int vol[],int n,int another)<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;int i=0,k;<BR>&nbsp;&nbsp;&nbsp;&nbsp;while (another&gt;vol[i])<BR>&nbsp;&nbsp;&nbsp;&nbsp;{i++;}<BR><BR>&nbsp;&nbsp; for (k=n;k=i;k--)&nbsp;&nbsp;//for (k=n;k&gt;i;k--)<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vol[k]=vol[k-1];<BR>&nbsp;&nbsp; }<BR>&nbsp;&nbsp; vol[k]=another;<BR>&nbsp;&nbsp; cout &lt;&lt;"notice:";<BR>&nbsp;&nbsp; cout &lt;&lt;vol[k]&lt;&lt;endl;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return (n+1);<BR>}<BR><BR>main()最后:<BR>&nbsp;&nbsp; for (i=0;i&lt;m;i++)&nbsp;&nbsp;//for (i=0;i&lt;n;i++)<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout &lt;&lt;num[i]&lt;&lt;endl;<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;cout &lt;&lt;n&lt;&lt;endl;<BR>&nbsp;&nbsp;&nbsp;&nbsp;cin &gt;&gt;z;<BR>&nbsp;&nbsp;&nbsp;&nbsp;return 0;<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>

⌨️ 快捷键说明

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