﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-linxuex-最新评论</title><link>http://www.cppblog.com/linxuex/CommentsRSS.aspx</link><description>C++学习者</description><language>zh-cn</language><pubDate>Sat, 21 Apr 2007 01:39:04 GMT</pubDate><lastBuildDate>Sat, 21 Apr 2007 01:39:04 GMT</lastBuildDate><generator>cnblogs</generator><item><title>re: 请  教</title><link>http://www.cppblog.com/linxuex/archive/2007/04/28/22451.html#23138</link><dc:creator>pengkuny</dc:creator><author>pengkuny</author><pubDate>Sat, 28 Apr 2007 12:59:00 GMT</pubDate><guid>http://www.cppblog.com/linxuex/archive/2007/04/28/22451.html#23138</guid><description><![CDATA[内循环for(j=i; j&lt;n-1-i; j++)的j至少要固定一端, 两端都与i相关,必错. <br>正解如下:<br>for(i=0; i&lt;n; i++)//排序 <br>{<br>		for(j=0; j&lt;n-1-i; j++) <br>		{<br>			if(x[j] &gt; x[j+1]) <br>			{<br>			swap(x[j],x[j+1]);//标准库函数 <br>			}<br>		}<br>	}<img src ="http://www.cppblog.com/linxuex/aggbug/23138.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/linxuex/" target="_blank">pengkuny</a> 2007-04-28 20:59 <a href="http://www.cppblog.com/linxuex/archive/2007/04/28/22451.html#23138#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>re: 请  教</title><link>http://www.cppblog.com/linxuex/archive/2007/04/27/22451.html#23021</link><dc:creator>sandy</dc:creator><author>sandy</author><pubDate>Fri, 27 Apr 2007 03:03:00 GMT</pubDate><guid>http://www.cppblog.com/linxuex/archive/2007/04/27/22451.html#23021</guid><description><![CDATA[for(j=0;j&lt;5;j++) <br>for(i=j;i&lt;5-j;i++) <br>if(a[i]&gt;a[i+1]) <br>这里出问题了<br>当j=0，i=4时，a[i+1]是哪个元素啊~这时不是越界了。<br>所以我感觉应该是这样写：<br>template &lt;typename T&gt;<br>void sort(T v[],int size)<br>{<br>for(int i = 0;i &lt; size;++i)<br>  for(int j = i;j &lt; size - 1-i;++j)<br>    if(a[j]&gt;a[j+1])<br>     swap(a[j],a[j+1]);//标准库里好像有这个函数<br>}<br><br>用模板写就省很多功夫了<img src ="http://www.cppblog.com/linxuex/aggbug/23021.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/linxuex/" target="_blank">sandy</a> 2007-04-27 11:03 <a href="http://www.cppblog.com/linxuex/archive/2007/04/27/22451.html#23021#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>re: 请  教</title><link>http://www.cppblog.com/linxuex/archive/2007/04/22/22451.html#22577</link><dc:creator>chenger</dc:creator><author>chenger</author><pubDate>Sun, 22 Apr 2007 02:13:00 GMT</pubDate><guid>http://www.cppblog.com/linxuex/archive/2007/04/22/22451.html#22577</guid><description><![CDATA[用模板不是更好？<br>template &lt;typename T&gt;<br>void sort(T v[],int size)<br>{<br>for(int i = 0;i &lt; size;++i)<br>{<br>for(int j = i;j &lt; size - 1;++j)<br>{<br>if(a[j]&gt;a[j+1])<br>swap(a[j],a[j+1]);//标准库里好像有这个函数<br>}<br>}<br>}<br><br>不知道对不对……这个sort，如果代码没错的话，可以适用于所有能够用&lt;比较大小的类型，此外要支持赋值，总之要让swap函数能工作。当然，更好的办法是提供两个迭代器begin,end指明排序范围。建议楼主去看看STL里算法的实现。<img src ="http://www.cppblog.com/linxuex/aggbug/22577.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/linxuex/" target="_blank">chenger</a> 2007-04-22 10:13 <a href="http://www.cppblog.com/linxuex/archive/2007/04/22/22451.html#22577#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>re: 请  教</title><link>http://www.cppblog.com/linxuex/archive/2007/04/22/22451.html#22574</link><dc:creator>jarod-pku</dc:creator><author>jarod-pku</author><pubDate>Sun, 22 Apr 2007 01:11:00 GMT</pubDate><guid>http://www.cppblog.com/linxuex/archive/2007/04/22/22451.html#22574</guid><description><![CDATA[代码的毛病还是比较多的。<br><br>另外，VC6的库比较老，对&quot;iostream&quot;的支持不好。一般都是用.h的老库。<br><br>写成template要方便很多。<br><img src ="http://www.cppblog.com/linxuex/aggbug/22574.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/linxuex/" target="_blank">jarod-pku</a> 2007-04-22 09:11 <a href="http://www.cppblog.com/linxuex/archive/2007/04/22/22451.html#22574#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>re: 请  教</title><link>http://www.cppblog.com/linxuex/archive/2007/04/21/22451.html#22511</link><dc:creator>踏雪赤兔</dc:creator><author>踏雪赤兔</author><pubDate>Sat, 21 Apr 2007 10:57:00 GMT</pubDate><guid>http://www.cppblog.com/linxuex/archive/2007/04/21/22451.html#22511</guid><description><![CDATA[怎么不写成template<img src ="http://www.cppblog.com/linxuex/aggbug/22511.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/linxuex/" target="_blank">踏雪赤兔</a> 2007-04-21 18:57 <a href="http://www.cppblog.com/linxuex/archive/2007/04/21/22451.html#22511#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>re: 请  教</title><link>http://www.cppblog.com/linxuex/archive/2007/04/21/22451.html#22495</link><dc:creator>pengkuny</dc:creator><author>pengkuny</author><pubDate>Sat, 21 Apr 2007 07:36:00 GMT</pubDate><guid>http://www.cppblog.com/linxuex/archive/2007/04/21/22451.html#22495</guid><description><![CDATA[for(j=0;j&lt;5;j++) <br>{ <br>for(i=0;i&lt;5-j;i++) <br>{ <br>if(a[i]&gt;a[i+1]) <br>...}<br>}<br>怎么没越界,j = 0, i = 4, a[i+1]越界a[5]!<br>我前面写错了, 外循环不要改, 改后如下:<br>for(j=0;j&lt;5;j++) <br>{ <br>for(i=0;i&lt;4-j;i++) //内循环改一下<br>{ <br>if(a[i]&gt;a[i+1]) <br>...}<br>}<br><br><br>我运行结果良好,怎么会调不出来<img src ="http://www.cppblog.com/linxuex/aggbug/22495.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/linxuex/" target="_blank">pengkuny</a> 2007-04-21 15:36 <a href="http://www.cppblog.com/linxuex/archive/2007/04/21/22451.html#22495#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>re: 请  教</title><link>http://www.cppblog.com/linxuex/archive/2007/04/21/22451.html#22493</link><dc:creator>tivili_chen</dc:creator><author>tivili_chen</author><pubDate>Sat, 21 Apr 2007 06:49:00 GMT</pubDate><guid>http://www.cppblog.com/linxuex/archive/2007/04/21/22451.html#22493</guid><description><![CDATA[#include&lt;iostream&gt;<br>#include&lt;string&gt;<br>using namespace std;<br>void sort(long []);<br>  void sort(int []);<br>  void sort(float []);<br>int main()<br>{ long a[5]={10100, -123567, 1198783, -165654, 3456};<br>  int b[5]={1,9,0,23,-45};<br>  float c[5]={2.4f,7.6f,5.5f,6.6f,-2.3f};<br>  <br>  sort(a);<br>  sort(b);<br>  sort(c);<br>  return 0;<br>}<br><br>void sort(long a[])<br>{int i,j;<br> long t;<br> for(j=0;j&lt;5;j++)<br>   for(i=0;i&lt;5-j;i++)<br>    if(a[i]&gt;a[i+1])<br>    {t=a[i];a[i]=a[i+1];a[i+1]=t;}<br> cout&lt;&lt;&quot;the sorted numbers:&quot;&lt;&lt;endl;<br> for(i=0;i&lt;5;i++)<br>  cout&lt;&lt;a[i]&lt;&lt;&quot; &quot;;<br> cout&lt;&lt;endl&lt;&lt;endl;<br>}<br><br>void sort(int a[])<br>{int i,j,t;<br> for(j=0;j&lt;5;j++)<br>   for(i=0;i&lt;5-j;i++)<br>    if(a[i]&gt;a[i+1])<br>    {t=a[i];a[i]=a[i+1];a[i+1]=t;}<br> cout&lt;&lt;&quot;the sorted numbers:&quot;&lt;&lt;endl;<br> for(i=0;i&lt;5;i++)<br>  cout&lt;&lt;a[i]&lt;&lt;&quot; &quot;;<br> cout&lt;&lt;endl&lt;&lt;endl;<br>}<br><br>void sort(float a[])<br>{int i,j;<br> float t;<br> for(j=0;j&lt;5;j++)<br>   for(i=0;i&lt;5-j;i++)<br>    if(a[i]&gt;a[i+1])<br>    {t=a[i];a[i]=a[i+1];a[i+1]=t;}<br> cout&lt;&lt;&quot;the sorted numbers:&quot;&lt;&lt;endl;<br> for(i=0;i&lt;5;i++)<br>  cout&lt;&lt;a[i]&lt;&lt;&quot; &quot;;<br> cout&lt;&lt;endl&lt;&lt;endl;<br>}<br><br><img src ="http://www.cppblog.com/linxuex/aggbug/22493.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/linxuex/" target="_blank">tivili_chen</a> 2007-04-21 14:49 <a href="http://www.cppblog.com/linxuex/archive/2007/04/21/22451.html#22493#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>re: 请  教</title><link>http://www.cppblog.com/linxuex/archive/2007/04/21/22451.html#22491</link><dc:creator>linxuex</dc:creator><author>linxuex</author><pubDate>Sat, 21 Apr 2007 06:38:00 GMT</pubDate><guid>http://www.cppblog.com/linxuex/archive/2007/04/21/22451.html#22491</guid><description><![CDATA[我觉得没越界j&lt;5表示j取0，1，2，3，4可表示5个数<br>若j&lt;4    j取0,1,2,3四个数<br>我调了一下你给的  没调出来<br><br><br><br>能不能帮我再调一下    谢谢！！！！！！！！！！！！！<img src ="http://www.cppblog.com/linxuex/aggbug/22491.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/linxuex/" target="_blank">linxuex</a> 2007-04-21 14:38 <a href="http://www.cppblog.com/linxuex/archive/2007/04/21/22451.html#22491#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>re: 请  教</title><link>http://www.cppblog.com/linxuex/archive/2007/04/21/22451.html#22458</link><dc:creator>wzqxp2002</dc:creator><author>wzqxp2002</author><pubDate>Sat, 21 Apr 2007 01:57:00 GMT</pubDate><guid>http://www.cppblog.com/linxuex/archive/2007/04/21/22451.html#22458</guid><description><![CDATA[干吗不用模版哦？<img src ="http://www.cppblog.com/linxuex/aggbug/22458.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/linxuex/" target="_blank">wzqxp2002</a> 2007-04-21 09:57 <a href="http://www.cppblog.com/linxuex/archive/2007/04/21/22451.html#22458#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>re: 请  教</title><link>http://www.cppblog.com/linxuex/archive/2007/04/21/22451.html#22457</link><dc:creator>pengkuny</dc:creator><author>pengkuny</author><pubDate>Sat, 21 Apr 2007 01:52:00 GMT</pubDate><guid>http://www.cppblog.com/linxuex/archive/2007/04/21/22451.html#22457</guid><description><![CDATA[算了,编译了一下:<br>#include &quot;stdafx.h&quot;<br>#include&lt;iostream&gt;<br>//#include&lt;string&gt;<br><br>using namespace std;<br><br>int main()<br>{ <br>	long a[5]={10100, -123567, 1198783, -165654, 3456};<br>	int b[5]={1,9,0,23,-45};<br>	double c[5]={2.4,7.6,5.5,6.6,-2.3};<br>	void sort(long []);<br>	void sort(int []);<br>	void sort(double []);<br>	sort(a);<br>	sort(b);<br>	sort(c);<br>	return 0;<br>	system(&quot;pause&quot;);<br>}<br><br>void sort(long a[])<br>{<br>	int i,j;<br>	long t;<br>	for(j=0;j&lt;4;j++)<br>	{<br>		for(i=0;i&lt;4-j;i++)<br>		{<br>			if(a[i]&gt;a[i+1])<br>			{<br>				t=a[i];a[i]=a[i+1];a[i+1]=t;<br>			}<br>		}<br>	}<br>	cout&lt;&lt;&quot;the sorted numbers:&quot;&lt;&lt;endl;<br>	for(i=0;i&lt;5;i++)<br>		cout&lt;&lt;a[i]&lt;&lt;&quot; &quot;;<br>	cout&lt;&lt;endl&lt;&lt;endl;<br>	system(&quot;pause&quot;);<br>}<br><br>void sort(int a[])<br>{<br>	int i,j,t;<br>	for(j=0;j&lt;4;j++)<br>	{<br>		for(i=0;i&lt;4-j;i++)<br>		{<br>			if(a[i]&gt;a[i+1])<br>			{<br>				t=a[i];a[i]=a[i+1];a[i+1]=t;<br>			}<br>		}<br>	}<br>	cout&lt;&lt;&quot;the sorted numbers:&quot;&lt;&lt;endl;<br>	for(i=0;i&lt;5;i++)<br>		cout&lt;&lt;a[i]&lt;&lt;&quot; &quot;;<br>	cout&lt;&lt;endl&lt;&lt;endl;<br>	system(&quot;pause&quot;);<br>}<br><br>void sort(double a[])<br>{<br>	int i,j;<br>	double t;<br>	for(j=0;j&lt;4;j++)<br>	{<br>		for(i=0;i&lt;4-j;i++)<br>		{<br>			if(a[i]&gt;a[i+1])<br>			{<br>				t=a[i];a[i]=a[i+1];a[i+1]=t;<br>			}<br>		}<br>	}<br>	cout&lt;&lt;&quot;the sorted numbers:&quot;&lt;&lt;endl;<br>	for(i=0;i&lt;5;i++)<br>		cout&lt;&lt;a[i]&lt;&lt;&quot; &quot;;<br>	cout&lt;&lt;endl&lt;&lt;endl;<br>	system(&quot;pause&quot;);<br>}<img src ="http://www.cppblog.com/linxuex/aggbug/22457.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/linxuex/" target="_blank">pengkuny</a> 2007-04-21 09:52 <a href="http://www.cppblog.com/linxuex/archive/2007/04/21/22451.html#22457#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>