﻿<?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++博客-ask-how</title><link>http://www.cppblog.com/ask-how/</link><description /><language>zh-cn</language><lastBuildDate>Wed, 08 Apr 2026 02:40:38 GMT</lastBuildDate><pubDate>Wed, 08 Apr 2026 02:40:38 GMT</pubDate><ttl>60</ttl><item><title>static</title><link>http://www.cppblog.com/ask-how/archive/2012/06/02/177244.html</link><dc:creator>千万次的问</dc:creator><author>千万次的问</author><pubDate>Sat, 02 Jun 2012 14:15:00 GMT</pubDate><guid>http://www.cppblog.com/ask-how/archive/2012/06/02/177244.html</guid><wfw:comment>http://www.cppblog.com/ask-how/comments/177244.html</wfw:comment><comments>http://www.cppblog.com/ask-how/archive/2012/06/02/177244.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/ask-how/comments/commentRss/177244.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ask-how/services/trackbacks/177244.html</trackback:ping><description><![CDATA[术语static有着不寻常的历史。起初，在C中引入关键字static是为了表示退出一个块后仍然存在的局部变量。随后，static C中有了第二种含义：用来表示不能被其它文件访问的全局变量和函数。为了避免引入新的关键字，所以仍使用static关键字来表示这第二种含义。最后，C++重用了这个关键字，并赋予它与前面不同的第三种含义：表示属于一个类而不是属于此类的任何特定对象的变量和函数(与Java中此关键字的含义相同)。<br /><br />参见文章：<br /><a href="http://club.topsage.com/thread-2504320-1-1.html">http://club.topsage.com/thread-2504320-1-1.html</a><br /><a href="http://baike.baidu.com/view/536145.htm">http://baike.baidu.com/view/536145.htm</a><br /><img src ="http://www.cppblog.com/ask-how/aggbug/177244.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ask-how/" target="_blank">千万次的问</a> 2012-06-02 22:15 <a href="http://www.cppblog.com/ask-how/archive/2012/06/02/177244.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>冒泡里的n</title><link>http://www.cppblog.com/ask-how/archive/2012/05/18/175329.html</link><dc:creator>千万次的问</dc:creator><author>千万次的问</author><pubDate>Fri, 18 May 2012 12:20:00 GMT</pubDate><guid>http://www.cppblog.com/ask-how/archive/2012/05/18/175329.html</guid><wfw:comment>http://www.cppblog.com/ask-how/comments/175329.html</wfw:comment><comments>http://www.cppblog.com/ask-how/archive/2012/05/18/175329.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/ask-how/comments/commentRss/175329.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ask-how/services/trackbacks/175329.html</trackback:ping><description><![CDATA[<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; height: 818px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080">偶然遇到一个有意思的问题，先记下来<br /><br />&nbsp;1</span><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" /><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">stdio.h</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;2</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" /><br /></span><span style="color: #008080">&nbsp;3</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" /></span><span style="color: #0000ff">#define</span><span style="color: #000000">&nbsp;MAX&nbsp;10</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;4</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;a[MAX];<br /></span><span style="color: #008080">&nbsp;5</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;rand_seed&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">10</span><span style="color: #000000">;<br /></span><span style="color: #008080">&nbsp;6</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" /><br /></span><span style="color: #008080">&nbsp;7</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" /></span><span style="color: #008000">//</span><span style="color: #008000">return&nbsp;0~32767间一个随机数字</span><span style="color: #008000"><br /></span><span style="color: #008080">&nbsp;8</span><span style="color: #008000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;rand()<br /></span><span style="color: #008080">&nbsp;9</span><span style="color: #000000"><img id="Codehighlighter1_103_200_Open_Image" onclick="this.style.display='none'; Codehighlighter1_103_200_Open_Text.style.display='none'; Codehighlighter1_103_200_Closed_Image.style.display='inline'; Codehighlighter1_103_200_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"></span><span id="Codehighlighter1_103_200_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">10</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;rand_seed&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;rand_seed&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">110351245</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">12345</span><span style="color: #000000">;<br /></span><span style="color: #008080">11</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;(unsigned&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">)(rand_seed&nbsp;</span><span style="color: #000000">/</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">65536</span><span style="color: #000000">)&nbsp;</span><span style="color: #000000">%</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">32768</span><span style="color: #000000">;<br /></span><span style="color: #008080">12</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">13</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" /><br /></span><span style="color: #008080">14</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" /></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;bubble_sort(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;a[],</span><span style="color: #0000ff">const</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;n)<br /></span><span style="color: #008080">15</span><span style="color: #000000"><img id="Codehighlighter1_241_403_Open_Image" onclick="this.style.display='none'; Codehighlighter1_241_403_Open_Text.style.display='none'; Codehighlighter1_241_403_Closed_Image.style.display='inline'; Codehighlighter1_241_403_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"></span><span id="Codehighlighter1_241_403_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">16</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i,j,t;<br /></span><span style="color: #008080">17</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;<br /></span><span style="color: #008080">18</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;n;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">19</span><span style="color: #000000"><img id="Codehighlighter1_280_401_Open_Image" onclick="this.style.display='none'; Codehighlighter1_280_401_Open_Text.style.display='none'; Codehighlighter1_280_401_Closed_Image.style.display='inline'; Codehighlighter1_280_401_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_280_401_Closed_Text"></span><span id="Codehighlighter1_280_401_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">20</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(j&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;n&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;j&nbsp;</span><span style="color: #000000">&gt;=</span><span style="color: #000000">&nbsp;i;&nbsp;j</span><span style="color: #000000">--</span><span style="color: #000000">)<br /></span><span style="color: #008080">21</span><span style="color: #000000"><img id="Codehighlighter1_314_398_Open_Image" onclick="this.style.display='none'; Codehighlighter1_314_398_Open_Text.style.display='none'; Codehighlighter1_314_398_Closed_Image.style.display='inline'; Codehighlighter1_314_398_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_314_398_Closed_Text"></span><span id="Codehighlighter1_314_398_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">22</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(a[j]&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;a[j</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">])<br /></span><span style="color: #008080">23</span><span style="color: #000000"><img id="Codehighlighter1_340_394_Open_Image" onclick="this.style.display='none'; Codehighlighter1_340_394_Open_Text.style.display='none'; Codehighlighter1_340_394_Closed_Image.style.display='inline'; Codehighlighter1_340_394_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_340_394_Closed_Text"></span><span id="Codehighlighter1_340_394_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">24</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;a[j];<br /></span><span style="color: #008080">25</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a[j]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;a[j</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">];<br /></span><span style="color: #008080">26</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a[j</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;t;<br /></span><span style="color: #008080">27</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">28</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">29</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">30</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">31</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" /><br /></span><span style="color: #008080">32</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /></span><span style="color: #008080">33</span><span style="color: #000000"><img id="Codehighlighter1_417_639_Open_Image" onclick="this.style.display='none'; Codehighlighter1_417_639_Open_Text.style.display='none'; Codehighlighter1_417_639_Closed_Image.style.display='inline'; Codehighlighter1_417_639_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"></span><span id="Codehighlighter1_417_639_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">34</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i,j;<br /></span><span style="color: #008080">35</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /></span><span style="color: #008080">36</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">&nbsp;fill&nbsp;array</span><span style="color: #008000"><br /></span><span style="color: #008080">37</span><span style="color: #008000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;MAX;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">38</span><span style="color: #000000"><img id="Codehighlighter1_477_521_Open_Image" onclick="this.style.display='none'; Codehighlighter1_477_521_Open_Text.style.display='none'; Codehighlighter1_477_521_Closed_Image.style.display='inline'; Codehighlighter1_477_521_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_477_521_Closed_Text"></span><span id="Codehighlighter1_477_521_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">39</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a[i]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;rand();<br /></span><span style="color: #008080">40</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">%d </span><span style="color: #000000">"</span><span style="color: #000000">,a[i]);<br /></span><span style="color: #008080">41</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">42</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">\n</span><span style="color: #000000">"</span><span style="color: #000000">);<br /></span><span style="color: #008080">43</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;bubble_sort(a,&nbsp;MAX);<br /></span><span style="color: #008080">44</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;<br /></span><span style="color: #008080">45</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(j&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;j&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;MAX);&nbsp;j</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">46</span><span style="color: #000000"><img id="Codehighlighter1_591_618_Open_Image" onclick="this.style.display='none'; Codehighlighter1_591_618_Open_Text.style.display='none'; Codehighlighter1_591_618_Closed_Image.style.display='inline'; Codehighlighter1_591_618_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_591_618_Closed_Text"></span><span id="Codehighlighter1_591_618_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">47</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">%d </span><span style="color: #000000">"</span><span style="color: #000000">,a[j]);<br /></span><span style="color: #008080">48</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">49</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" /><br /></span><span style="color: #008080">50</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /></span><span style="color: #008080">51</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" />}</span></span></div>输出结果:<br /><br />
<p>16838 8723 13221 18534 18069 4560 3644 29292 25286 16198</p>
<p>3644 4560 8723 13221 16198 16838 18069 18534 25286 29292</p><br />若将bubble_sort如下定义<br />
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><img alt="" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" /><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;bubble_sort(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;a[])&nbsp; //</span><span style="color: red">与前者的区别是少传一个参数n </span><span style="color: #000000"><br /><img id="Codehighlighter1_26_221_Open_Image" onclick="this.style.display='none'; Codehighlighter1_26_221_Open_Text.style.display='none'; Codehighlighter1_26_221_Closed_Image.style.display='inline'; Codehighlighter1_26_221_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"></span><span id="Codehighlighter1_26_221_Open_Text"><span style="color: #000000">{<br /><img alt="" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i,j,t;<br /><img alt="" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;n&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(a)&nbsp;</span><span style="color: #000000">/</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(a[</span><span style="color: #000000">0</span><span style="color: #000000">]);&nbsp; //</span><span style="color: red">数组</span><span style="color: red">大小在函数内部获取&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000"><br /><img alt="" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" /></span><span style="color: #0000ff">for</span><span style="color: #000000">(i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;n;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /><img id="Codehighlighter1_98_219_Open_Image" onclick="this.style.display='none'; Codehighlighter1_98_219_Open_Text.style.display='none'; Codehighlighter1_98_219_Closed_Image.style.display='inline'; Codehighlighter1_98_219_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_98_219_Closed_Text"></span><span id="Codehighlighter1_98_219_Open_Text"><span style="color: #000000">{<br /><img alt="" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(j&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;n&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;&nbsp;j&nbsp;</span><span style="color: #000000">&gt;=</span><span style="color: #000000">&nbsp;i;&nbsp;j</span><span style="color: #000000">--</span><span style="color: #000000">)<br /><img id="Codehighlighter1_132_216_Open_Image" onclick="this.style.display='none'; Codehighlighter1_132_216_Open_Text.style.display='none'; Codehighlighter1_132_216_Closed_Image.style.display='inline'; Codehighlighter1_132_216_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_132_216_Closed_Text"></span><span id="Codehighlighter1_132_216_Open_Text"><span style="color: #000000">{<br /><img alt="" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(a[j]&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;a[j</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">])<br /><img id="Codehighlighter1_158_212_Open_Image" onclick="this.style.display='none'; Codehighlighter1_158_212_Open_Text.style.display='none'; Codehighlighter1_158_212_Closed_Image.style.display='inline'; Codehighlighter1_158_212_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_158_212_Closed_Text"></span><span id="Codehighlighter1_158_212_Open_Text"><span style="color: #000000">{<br /><img alt="" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;a[j];<br /><img alt="" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a[j]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;a[j</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">];<br /><img alt="" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a[j</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;t;<br /><img alt="" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img alt="" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img alt="" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img alt="" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" />}</span></span></div>再调用排序<br />
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><img alt="" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" /><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /><img id="Codehighlighter1_11_243_Open_Image" onclick="this.style.display='none'; Codehighlighter1_11_243_Open_Text.style.display='none'; Codehighlighter1_11_243_Closed_Image.style.display='inline'; Codehighlighter1_11_243_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"></span><span id="Codehighlighter1_11_243_Open_Text"><span style="color: #000000">{<br /><img alt="" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i,j;<br /><img alt="" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /><img alt="" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">&nbsp;fill&nbsp;array</span><span style="color: #008000"><br /><img alt="" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;MAX;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /><img id="Codehighlighter1_67_111_Open_Image" onclick="this.style.display='none'; Codehighlighter1_67_111_Open_Text.style.display='none'; Codehighlighter1_67_111_Closed_Image.style.display='inline'; Codehighlighter1_67_111_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_67_111_Closed_Text"></span><span id="Codehighlighter1_67_111_Open_Text"><span style="color: #000000">{<br /><img alt="" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a[i]&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;rand();<br /><img alt="" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">%d </span><span style="color: #000000">"</span><span style="color: #000000">,a[i]);<br /><img alt="" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img alt="" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">\n</span><span style="color: #000000">"</span><span style="color: #000000">);<br /><img alt="" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;bubble_sort(a);<br /><img alt="" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;<br /><img alt="" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(j&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;j&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(a)&nbsp;</span><span style="color: #000000">/</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(a[</span><span style="color: #000000">0</span><span style="color: #000000">]);&nbsp;j</span><span style="color: #000000">++</span><span style="color: #000000">)<br /><img id="Codehighlighter1_196_223_Open_Image" onclick="this.style.display='none'; Codehighlighter1_196_223_Open_Text.style.display='none'; Codehighlighter1_196_223_Closed_Image.style.display='inline'; Codehighlighter1_196_223_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_196_223_Closed_Text"></span><span id="Codehighlighter1_196_223_Open_Text"><span style="color: #000000">{<br /><img alt="" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">%d </span><span style="color: #000000">"</span><span style="color: #000000">,a[j]);<br /><img alt="" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img alt="" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img alt="" align="top" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" />}</span></span></div>输出结果没有排序<br /><br />16838 8723 13221 18534 18069 4560 3644 29292 25286 16198<br />16838 8723 13221 18534 18069 4560 3644 29292 25286 16198<br /><br />n的奥妙啊。。 <img src ="http://www.cppblog.com/ask-how/aggbug/175329.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ask-how/" target="_blank">千万次的问</a> 2012-05-18 20:20 <a href="http://www.cppblog.com/ask-how/archive/2012/05/18/175329.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>