锘??xml version="1.0" encoding="utf-8" standalone="yes"?>国产亚洲免费的视频看,欧美激情综合色,欧美在线播放视频http://www.shnenglu.com/bujiwu/archive/2008/10/28/65383.htmlbujiwubujiwuTue, 28 Oct 2008 12:47:00 GMThttp://www.shnenglu.com/bujiwu/archive/2008/10/28/65383.htmlhttp://www.shnenglu.com/bujiwu/comments/65383.htmlhttp://www.shnenglu.com/bujiwu/archive/2008/10/28/65383.html#Feedback0http://www.shnenglu.com/bujiwu/comments/commentRss/65383.htmlhttp://www.shnenglu.com/bujiwu/services/trackbacks/65383.html  1 #include <assert.h>  2   3 template<typ...  闃呰鍏ㄦ枃

bujiwu 2008-10-28 20:47 鍙戣〃璇勮
]]>
鍫嗘帓搴忕畻娉曟葷粨錛?/title><link>http://www.shnenglu.com/bujiwu/archive/2008/10/26/65146.html</link><dc:creator>bujiwu</dc:creator><author>bujiwu</author><pubDate>Sun, 26 Oct 2008 14:21:00 GMT</pubDate><guid>http://www.shnenglu.com/bujiwu/archive/2008/10/26/65146.html</guid><wfw:comment>http://www.shnenglu.com/bujiwu/comments/65146.html</wfw:comment><comments>http://www.shnenglu.com/bujiwu/archive/2008/10/26/65146.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/bujiwu/comments/commentRss/65146.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/bujiwu/services/trackbacks/65146.html</trackback:ping><description><![CDATA[1銆?鍫嗘帓搴忓畾涔? <br> n涓叧閿瓧搴忓垪Kl錛孠2錛?#8230;錛孠n縐頒負鍫嗭紝褰撲笖浠呭綋璇ュ簭鍒楁弧瓚沖涓嬫ц川(綆縐頒負鍫嗘ц川)錛? <br> (1) ki≤K2i涓攌i≤K2i+1 鎴?2)Ki≥K2i涓攌i≥K2i+1(1≤i≤ ) <br> <br> 鑻ュ皢姝ゅ簭鍒楁墍瀛樺偍鐨勫悜閲廟[1..n]鐪嬪仛鏄竴媯靛畬鍏ㄤ簩鍙夋爲鐨勫瓨鍌ㄧ粨鏋勶紝鍒欏爢瀹炶川涓婃槸婊¤凍濡備笅鎬ц川鐨勫畬鍏ㄤ簩鍙夋爲錛氭爲涓換涓闈炲彾緇撶偣鐨勫叧閿瓧鍧囦笉澶т簬(鎴栦笉灝忎簬)鍏跺乏鍙沖瀛?鑻ュ瓨鍦?緇撶偣鐨勫叧閿瓧銆? <br>銆愪緥銆戝叧閿瓧搴忓垪(10錛?5錛?6錛?5錛?0錛?0)鍜?70錛?6錛?0錛?5錛?5錛?0)鍒嗗埆婊¤凍鍫嗘ц川(1)鍜?2)錛屾晠瀹冧滑鍧囨槸鍫嗭紝鍏跺搴旂殑瀹屽叏浜屽弶鏍戝垎鍒灝忔牴鍫嗙ず渚嬪拰澶ф牴鍫嗙ず渚嬫墍紺恒? <br>2銆佸ぇ鏍瑰爢鍜屽皬鏍瑰爢 <br> 鏍圭粨鐐?浜︾О涓哄爢欏?鐨勫叧閿瓧鏄爢閲屾墍鏈夌粨鐐瑰叧閿瓧涓渶灝忚呯殑鍫嗙О涓哄皬鏍瑰爢銆? <br> 鏍圭粨鐐?浜︾О涓哄爢欏?鐨勫叧閿瓧鏄爢閲屾墍鏈夌粨鐐瑰叧閿瓧涓渶澶ц咃紝縐頒負澶ф牴鍫嗐? <br> 娉ㄦ剰錛? <br> 鈶犲爢涓換涓瀛愭爲浜︽槸鍫嗐? <br> 鈶′互涓婅璁虹殑鍫嗗疄闄呬笂鏄簩鍙夊爢(Binary Heap)錛岀被浼煎湴鍙畾涔塳鍙夊爢銆? <br>3銆佸爢鎺掑簭鐗圭偣 <br> 鍫嗘帓搴?HeapSort)鏄竴鏍戝艦閫夋嫨鎺掑簭銆? <br> 鍫嗘帓搴忕殑鐗圭偣鏄細鍦ㄦ帓搴忚繃紼嬩腑錛屽皢R[l..n]鐪嬫垚鏄竴媯靛畬鍏ㄤ簩鍙夋爲鐨勯『搴忓瓨鍌ㄧ粨鏋勶紝鍒╃敤瀹屽叏浜屽弶鏍戜腑鍙屼翰緇撶偣鍜屽瀛愮粨鐐逛箣闂寸殑鍐呭湪鍏崇郴銆愬弬瑙佷簩鍙夋爲鐨勯『搴忓瓨鍌ㄧ粨鏋勩戯紝鍦ㄥ綋鍓嶆棤搴忓尯涓夋嫨鍏抽敭瀛楁渶澶?鎴栨渶灝?鐨勮褰曘? <br>4銆佸爢鎺掑簭涓庣洿鎺ユ彃鍏ユ帓搴忕殑鍖哄埆 <br> 鐩存帴閫夋嫨鎺掑簭涓紝涓轟簡浠嶳[1..n]涓夊嚭鍏抽敭瀛楁渶灝忕殑璁板綍錛屽繀欏昏繘琛宯-1嬈℃瘮杈冿紝鐒跺悗鍦≧[2..n]涓夊嚭鍏抽敭瀛楁渶灝忕殑璁板綍錛屽張闇瑕佸仛n-2嬈℃瘮 杈冦備簨瀹炰笂錛屽悗闈㈢殑n-2嬈℃瘮杈冧腑錛屾湁璁稿姣旇緝鍙兘鍦ㄥ墠闈㈢殑n-1嬈℃瘮杈冧腑宸茬粡鍋氳繃錛屼絾鐢變簬鍓嶄竴瓚熸帓搴忔椂鏈繚鐣欒繖浜涙瘮杈冪粨鏋滐紝鎵浠ュ悗涓瓚熸帓搴忔椂鍙堥噸澶嶆墽琛? 浜嗚繖浜涙瘮杈冩搷浣溿? <br> 鍫嗘帓搴忓彲閫氳繃鏍戝艦緇撴瀯淇濆瓨閮ㄥ垎姣旇緝緇撴灉錛屽彲鍑忓皯姣旇緝嬈℃暟銆? <br>5銆佸爢鎺掑簭 <br> 鍫嗘帓搴忓埄鐢ㄤ簡澶ф牴鍫?鎴栧皬鏍瑰爢)鍫嗛《璁板綍鐨勫叧閿瓧鏈澶?鎴栨渶灝?榪欎竴鐗瑰緛錛屼嬌寰楀湪褰撳墠鏃犲簭鍖轟腑閫夊彇鏈澶?鎴栨渶灝?鍏抽敭瀛楃殑璁板綍鍙樺緱綆鍗曘?br><br> <div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: #008080;"> 1</span> <span style="color: #008000;">/*</span><span style="color: #008000;"><br></span><span style="color: #008080;"> 2</span> <span style="color: #008000;">鍫嗘帓搴?br></span><span style="color: #008080;"> 3</span> <span style="color: #008000;">(1)鐢ㄥぇ鏍瑰爢鎺掑簭鐨勫熀鏈濇兂<br></span><span style="color: #008080;"> 4</span> <span style="color: #008000;">鈶?nbsp;鍏堝皢鍒濆鏂囦歡R[1..n]寤烘垚涓涓ぇ鏍瑰爢錛屾鍫嗕負鍒濆鐨勬棤搴忓尯<br></span><span style="color: #008080;"> 5</span> <span style="color: #008000;">鈶?nbsp;鍐嶅皢鍏抽敭瀛楁渶澶х殑璁板綍R[1](鍗沖爢欏?鍜屾棤搴忓尯鐨勬渶鍚庝竴涓褰昍[n]浜ゆ崲錛?br></span><span style="color: #008080;"> 6</span> <span style="color: #008000;">鐢辨寰楀埌鏂扮殑鏃犲簭鍖篟[1..n-1]鍜屾湁搴忓尯R[n]錛屼笖婊¤凍R[1..n-1].keys≤R[n].key<br></span><span style="color: #008080;"> 7</span> <span style="color: #008000;">鈶?nbsp;鐢變簬浜ゆ崲鍚庢柊鐨勬牴R[1]鍙兘榪濆弽鍫嗘ц川錛屾晠搴斿皢褰撳墠鏃犲簭鍖篟[1..n-1]璋冩暣涓哄爢銆?br></span><span style="color: #008080;"> 8</span> <span style="color: #008000;">鐒跺悗鍐嶆灝哛[1..n-1]涓叧閿瓧鏈澶х殑璁板綍R[1]鍜岃鍖洪棿鐨勬渶鍚庝竴涓褰昍[n-1]浜ゆ崲錛?br></span><span style="color: #008080;"> 9</span> <span style="color: #008000;">鐢辨寰楀埌鏂扮殑鏃犲簭鍖篟[1..n-2]鍜屾湁搴忓尯R[n-1..n]錛屼笖浠嶆弧瓚沖叧緋籖[1..n- 2].keys≤R[n-1..n].keys錛?br></span><span style="color: #008080;">10</span> <span style="color: #008000;">鍚屾牱瑕佸皢R[1..n-2]璋冩暣涓哄爢銆?br></span><span style="color: #008080;">11</span> <span style="color: #008000;">……<br></span><span style="color: #008080;">12</span> <span style="color: #008000;">鐩村埌鏃犲簭鍖哄彧鏈変竴涓厓绱犱負姝€?br></span><span style="color: #008080;">13</span> <span style="color: #008000;">(2)澶ф牴鍫嗘帓搴忕畻娉曠殑鍩烘湰鎿嶄綔錛?br></span><span style="color: #008080;">14</span> <span style="color: #008000;">鈶?nbsp;鍒濆鍖栨搷浣滐細灝哛[1..n]鏋勯犱負鍒濆鍫嗭紱<br></span><span style="color: #008080;">15</span> <span style="color: #008000;">鈶?nbsp;姣忎竴瓚熸帓搴忕殑鍩烘湰鎿嶄綔錛氬皢褰撳墠鏃犲簭鍖虹殑鍫嗛《璁板綍R[1]鍜岃鍖洪棿鐨勬渶鍚庝竴涓褰曚氦鎹紝鐒跺悗灝嗘柊鐨勬棤搴忓尯璋冩暣涓哄爢(浜︾О閲嶅緩鍫?銆?br></span><span style="color: #008080;">16</span> <span style="color: #008000;">娉ㄦ剰錛?br></span><span style="color: #008080;">17</span> <span style="color: #008000;">鈶犲彧闇鍋歯-1瓚熸帓搴忥紝閫夊嚭杈冨ぇ鐨刵-1涓叧閿瓧鍗沖彲浠ヤ嬌寰楁枃浠墮掑鏈夊簭銆?br></span><span style="color: #008080;">18</span> <span style="color: #008000;">鈶$敤灝忔牴鍫嗘帓搴忎笌鍒╃敤澶ф牴鍫嗙被浼鹼紝鍙笉榪囧叾鎺掑簭緇撴灉鏄掑噺鏈夊簭鐨勩?br></span><span style="color: #008080;">19</span> <span style="color: #008000;">鍫嗘帓搴忓拰鐩存帴閫夋嫨鎺掑簭鐩稿弽錛氬湪浠諱綍鏃跺埢錛屽爢鎺掑簭涓棤搴忓尯鎬繪槸鍦ㄦ湁搴忓尯涔嬪墠錛?br></span><span style="color: #008080;">20</span> <span style="color: #008000;">涓旀湁搴忓尯鏄湪鍘熷悜閲忕殑灝鵑儴鐢卞悗寰鍓嶉愭鎵╁ぇ鑷蟲暣涓悜閲忎負姝€?nbsp;<br></span><span style="color: #008080;">21</span> <span style="color: #008000;"></span><span style="color: #008000;">*/</span><span style="color: #000000;"><br></span><span style="color: #008080;">22</span> <span style="color: #000000;"><br></span><span style="color: #008080;">23</span> <span style="color: #000000;"></span><span style="color: #008000;">//</span><span style="color: #008000;">鐢熸垚澶ф牴鍫?/span><span style="color: #008000;"><br></span><span style="color: #008080;">24</span> <span style="color: #008000;"></span><span style="color: #0000ff;">void</span><span style="color: #000000;"> HeapAdjust(</span><span style="color: #0000ff;">int</span><span style="color: #000000;"> SortData[],</span><span style="color: #0000ff;">int</span><span style="color: #000000;"> StartIndex, </span><span style="color: #0000ff;">int</span><span style="color: #000000;"> Length)<br></span><span style="color: #008080;">25</span> <span style="color: #000000;">{<br></span><span style="color: #008080;">26</span> <span style="color: #000000;">    </span><span style="color: #0000ff;">while</span><span style="color: #000000;">(</span><span style="color: #000000;">2</span><span style="color: #000000;">*</span><span style="color: #000000;">StartIndex</span><span style="color: #000000;">+</span><span style="color: #000000;">1</span><span style="color: #000000;"> </span><span style="color: #000000;"><</span><span style="color: #000000;"> Length)<br></span><span style="color: #008080;">27</span> <span style="color: #000000;">    {<br></span><span style="color: #008080;">28</span> <span style="color: #000000;">        </span><span style="color: #0000ff;">int</span><span style="color: #000000;"> MinChildrenIndex </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #000000;">2</span><span style="color: #000000;">*</span><span style="color: #000000;">StartIndex</span><span style="color: #000000;">+</span><span style="color: #000000;">1</span><span style="color: #000000;"> ;<br></span><span style="color: #008080;">29</span> <span style="color: #000000;">        </span><span style="color: #0000ff;">if</span><span style="color: #000000;">(</span><span style="color: #000000;">2</span><span style="color: #000000;">*</span><span style="color: #000000;">StartIndex</span><span style="color: #000000;">+</span><span style="color: #000000;">2</span><span style="color: #000000;"> </span><span style="color: #000000;"><</span><span style="color: #000000;"> Length )<br></span><span style="color: #008080;">30</span> <span style="color: #000000;">        {<br></span><span style="color: #008080;">31</span> <span style="color: #000000;">            </span><span style="color: #008000;">//</span><span style="color: #008000;">姣旇緝宸﹀瓙鏍戝拰鍙沖瓙鏍戯紝璁板綍鏈澶у肩殑Index</span><span style="color: #008000;"><br></span><span style="color: #008080;">32</span> <span style="color: #008000;"></span><span style="color: #000000;">            </span><span style="color: #0000ff;">if</span><span style="color: #000000;">(SortData[</span><span style="color: #000000;">2</span><span style="color: #000000;">*</span><span style="color: #000000;">StartIndex</span><span style="color: #000000;">+</span><span style="color: #000000;">1</span><span style="color: #000000;">]</span><span style="color: #000000;"><</span><span style="color: #000000;">SortData[</span><span style="color: #000000;">2</span><span style="color: #000000;">*</span><span style="color: #000000;">StartIndex</span><span style="color: #000000;">+</span><span style="color: #000000;">2</span><span style="color: #000000;">])<br></span><span style="color: #008080;">33</span> <span style="color: #000000;">            {<br></span><span style="color: #008080;">34</span> <span style="color: #000000;">                MinChildrenIndex </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #000000;">2</span><span style="color: #000000;">*</span><span style="color: #000000;">StartIndex</span><span style="color: #000000;">+</span><span style="color: #000000;">2</span><span style="color: #000000;">;<br></span><span style="color: #008080;">35</span> <span style="color: #000000;">            }<br></span><span style="color: #008080;">36</span> <span style="color: #000000;">        }<br></span><span style="color: #008080;">37</span> <span style="color: #000000;">        </span><span style="color: #0000ff;">if</span><span style="color: #000000;">(SortData[StartIndex] </span><span style="color: #000000;"><</span><span style="color: #000000;"> SortData[MinChildrenIndex])<br></span><span style="color: #008080;">38</span> <span style="color: #000000;">        {<br></span><span style="color: #008080;">39</span> <span style="color: #000000;">            </span><span style="color: #008000;">//</span><span style="color: #008000;">浜ゆ崲i涓嶮inChildrenIndex鐨勬暟鎹?/span><span style="color: #008000;"><br></span><span style="color: #008080;">40</span> <span style="color: #008000;"></span><span style="color: #000000;">            </span><span style="color: #0000ff;">int</span><span style="color: #000000;"> tmpData </span><span style="color: #000000;">=</span><span style="color: #000000;">SortData[StartIndex];<br></span><span style="color: #008080;">41</span> <span style="color: #000000;">            SortData[StartIndex] </span><span style="color: #000000;">=</span><span style="color: #000000;">SortData[MinChildrenIndex];<br></span><span style="color: #008080;">42</span> <span style="color: #000000;">            SortData[MinChildrenIndex] </span><span style="color: #000000;">=</span><span style="color: #000000;">tmpData;<br></span><span style="color: #008080;">43</span> <span style="color: #000000;">            </span><span style="color: #008000;">//</span><span style="color: #008000;">鍫嗚鐮村潖錛岄渶瑕侀噸鏂拌皟鏁?/span><span style="color: #008000;"><br></span><span style="color: #008080;">44</span> <span style="color: #008000;"></span><span style="color: #000000;">            StartIndex </span><span style="color: #000000;">=</span><span style="color: #000000;"> MinChildrenIndex ;<br></span><span style="color: #008080;">45</span> <span style="color: #000000;">        }<br></span><span style="color: #008080;">46</span> <span style="color: #000000;">        </span><span style="color: #0000ff;">else</span><span style="color: #000000;"><br></span><span style="color: #008080;">47</span> <span style="color: #000000;">        {<br></span><span style="color: #008080;">48</span> <span style="color: #000000;">            </span><span style="color: #008000;">//</span><span style="color: #008000;">姣旇緝宸﹀彸瀛╁瓙鍧囧ぇ鍒欏爢鏈牬鍧忥紝涓嶅啀闇瑕佽皟鏁?/span><span style="color: #008000;"><br></span><span style="color: #008080;">49</span> <span style="color: #008000;"></span><span style="color: #000000;">            </span><span style="color: #0000ff;">break</span><span style="color: #000000;">;<br></span><span style="color: #008080;">50</span> <span style="color: #000000;">        }<br></span><span style="color: #008080;">51</span> <span style="color: #000000;">    }<br></span><span style="color: #008080;">52</span> <span style="color: #000000;"><br></span><span style="color: #008080;">53</span> <span style="color: #000000;">    </span><span style="color: #0000ff;">return</span><span style="color: #000000;">;<br></span><span style="color: #008080;">54</span> <span style="color: #000000;">}<br></span><span style="color: #008080;">55</span> <span style="color: #000000;"><br></span><span style="color: #008080;">56</span> <span style="color: #000000;"></span><span style="color: #008000;">//</span><span style="color: #008000;">鍫嗘帓搴?/span><span style="color: #008000;"><br></span><span style="color: #008080;">57</span> <span style="color: #008000;"></span><span style="color: #0000ff;">void</span><span style="color: #000000;"> HeapSortData(</span><span style="color: #0000ff;">int</span><span style="color: #000000;"> SortData[], </span><span style="color: #0000ff;">int</span><span style="color: #000000;"> Length)<br></span><span style="color: #008080;">58</span> <span style="color: #000000;">{<br></span><span style="color: #008080;">59</span> <span style="color: #000000;">    </span><span style="color: #0000ff;">int</span><span style="color: #000000;"> i</span><span style="color: #000000;">=</span><span style="color: #000000;">0</span><span style="color: #000000;">;<br></span><span style="color: #008080;">60</span> <span style="color: #000000;"><br></span><span style="color: #008080;">61</span> <span style="color: #000000;">    </span><span style="color: #008000;">//</span><span style="color: #008000;">灝咹r[0,Lenght-1]寤烘垚澶ф牴鍫?/span><span style="color: #008000;"><br></span><span style="color: #008080;">62</span> <span style="color: #008000;"></span><span style="color: #000000;">    </span><span style="color: #0000ff;">for</span><span style="color: #000000;"> (i</span><span style="color: #000000;">=</span><span style="color: #000000;">Length</span><span style="color: #000000;">/</span><span style="color: #000000;">2</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">; i</span><span style="color: #000000;">>=</span><span style="color: #000000;">0</span><span style="color: #000000;">; i</span><span style="color: #000000;">--</span><span style="color: #000000;">)<br></span><span style="color: #008080;">63</span> <span style="color: #000000;">    {<br></span><span style="color: #008080;">64</span> <span style="color: #000000;">        HeapAdjust(SortData, i, Length);<br></span><span style="color: #008080;">65</span> <span style="color: #000000;">    }<br></span><span style="color: #008080;">66</span> <span style="color: #000000;"><br></span><span style="color: #008080;">67</span> <span style="color: #000000;">    </span><span style="color: #0000ff;">for</span><span style="color: #000000;"> (i</span><span style="color: #000000;">=</span><span style="color: #000000;">Length</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">; i</span><span style="color: #000000;">></span><span style="color: #000000;">0</span><span style="color: #000000;">; i</span><span style="color: #000000;">--</span><span style="color: #000000;">)<br></span><span style="color: #008080;">68</span> <span style="color: #000000;">    {<br></span><span style="color: #008080;">69</span> <span style="color: #000000;">        </span><span style="color: #008000;">//</span><span style="color: #008000;">涓庢渶鍚庝竴涓褰曚氦鎹?/span><span style="color: #008000;"><br></span><span style="color: #008080;">70</span> <span style="color: #008000;"></span><span style="color: #000000;">        </span><span style="color: #0000ff;">int</span><span style="color: #000000;"> tmpData </span><span style="color: #000000;">=</span><span style="color: #000000;">SortData[</span><span style="color: #000000;">0</span><span style="color: #000000;">];<br></span><span style="color: #008080;">71</span> <span style="color: #000000;">        SortData[</span><span style="color: #000000;">0</span><span style="color: #000000;">] </span><span style="color: #000000;">=</span><span style="color: #000000;">SortData[i];<br></span><span style="color: #008080;">72</span> <span style="color: #000000;">        SortData[i] </span><span style="color: #000000;">=</span><span style="color: #000000;">tmpData;<br></span><span style="color: #008080;">73</span> <span style="color: #000000;">        </span><span style="color: #008000;">//</span><span style="color: #008000;">灝咹.r[0..i]閲嶆柊璋冩暣涓哄ぇ鏍瑰爢</span><span style="color: #008000;"><br></span><span style="color: #008080;">74</span> <span style="color: #008000;"></span><span style="color: #000000;">        HeapAdjust(SortData, </span><span style="color: #000000;">0</span><span style="color: #000000;">, i);<br></span><span style="color: #008080;">75</span> <span style="color: #000000;">    }<br></span><span style="color: #008080;">76</span> <span style="color: #000000;">  <br></span><span style="color: #008080;">77</span> <span style="color: #000000;">    </span><span style="color: #0000ff;">return</span><span style="color: #000000;">;<br></span><span style="color: #008080;">78</span> <span style="color: #000000;">}</span></div> <br><span style="font-weight: bold;">CODE:</span><a href="http://www.shnenglu.com/Files/bujiwu/HeapSort.rar">http://www.shnenglu.com/Files/bujiwu/HeapSort.rar</a><br>鍙傝冩枃绔狅細<br><a >http://www.cnblogs.com/xiaotao823/articles/1055399.html</a><br><a >http://zhidao.baidu.com/question/1003067.html</a><br> <img src ="http://www.shnenglu.com/bujiwu/aggbug/65146.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/bujiwu/" target="_blank">bujiwu</a> 2008-10-26 22:21 <a href="http://www.shnenglu.com/bujiwu/archive/2008/10/26/65146.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>鍑犵鍐呴儴鎺掑簭綆楁硶鎬葷粨!(鍐掓場鎺掑簭銆佸揩閫熸帓搴忋佺洿鎺ユ彃鍏ユ帓搴忋佹媶鍗婃彃鍏ユ帓搴忋佺畝鍗曢夋嫨鎺掑簭)http://www.shnenglu.com/bujiwu/archive/2008/10/25/65040.htmlbujiwubujiwuSat, 25 Oct 2008 15:53:00 GMThttp://www.shnenglu.com/bujiwu/archive/2008/10/25/65040.htmlhttp://www.shnenglu.com/bujiwu/comments/65040.htmlhttp://www.shnenglu.com/bujiwu/archive/2008/10/25/65040.html#Feedback1http://www.shnenglu.com/bujiwu/comments/commentRss/65040.htmlhttp://www.shnenglu.com/bujiwu/services/trackbacks/65040.html  1 #include <iostream>
  2 using namespace std;
  3 
  4 /*/////////////////////////////////////////////////////////////////////////
  5 浠ヤ笅涓哄揩閫熸帓搴?br>  6 /////////////////////////////////////////////////////////////////////////*/
  7 /*
  8 鍐掓場鎺掑簭
  9 綆楁硶錛?br> 10 鏍稿績鎬濇兂鏄壂鎻忔暟鎹竻鍗曪紝瀵繪壘鍑虹幇涔卞簭鐨勪袱涓浉閭葷殑欏圭洰銆傚綋鎵懼埌榪欎袱涓」鐩悗
 11 浜ゆ崲欏圭洰鐨勪綅緗劧鍚庣戶緇壂鎻忋傞噸澶嶄笂闈㈢殑鎿嶄綔鐩村埌鎵鏈夌殑欏圭洰閮芥寜欏哄簭鎺掑ソ
 12 鏃墮棿澶嶆潅搴*n  (n-1)*n/2
 13 */
 14 void BubbleSortData(int SortData[], int Length)
 15 {
 16     int tmpData =0;
 17     bool swapFlag =true;
 18 
 19     for (int i=Length-1; i>0 && swapFlag; i--)
 20     {
 21         swapFlag =false;
 22         for(int j=0; j<i; j++)
 23         {
 24             if ( SortData[j] > SortData[j+1])
 25             {
 26                 tmpData =SortData[j];
 27                 SortData[j] =SortData[j+1];
 28                 SortData[j+1=tmpData;
 29                 swapFlag =true;
 30             }
 31         }
 32     }
 33 
 34     return;
 35 }
 36 /*
 37 蹇熸帓搴忔槸瀵硅搗娉℃帓搴忕殑涓縐嶆敼榪涳紝閫氳繃涓瓚熸帓搴忓皢寰呮帓搴忚褰曞垎鍓叉垚鐙珛鐨勪袱閮ㄥ垎錛屽叾涓竴閮ㄥ垎璁板綍鐨勫叧閿瓧鍧囨瘮鍙︿竴閮ㄥ垎璁板綍鐨勫叧閿?br> 38 瀛楀皬錛屽垯鍙垎鍒榪欎袱閮ㄥ垎緇х畫榪涜鎺掑簭錛屼互杈懼埌鏁翠釜搴忓垪鏈夊簭.
 39 浜ゆ崲欏哄簭琛↙涓瓙琛↙.r[low..high]鐨勮褰曪紝浣挎灑杞磋褰曞埌浣嶏紝騫惰繑鍥炲叾鎵鍦ㄤ綅緗紝姝ゆ椂鍦ㄥ畠涔嬪墠(鍚?鐨勮褰曞潎涓嶅ぇ(灝?浜庡畠
 40 鏃墮棿澶嶆潅搴︿負 n*logn,鍏跺鉤鍧囨ц兘鏈濂斤紝鑻ュ垵濮嬭褰曞簭鍒楁寜鍏抽敭瀛楁湁搴忔垨鍩烘湰鏈夊簭錛屽揩閫熸帓搴忓皢閿愬寲涓鴻搗娉℃帓搴?br> 41 */
 42 int  Partition(int SortData[], int low, int high)
 43 {
 44     int tmpData =SortData[low];//鐢ㄤ簬瀛愯〃鐨勭涓涓褰曚綔鏋㈣醬璁板綍
 45     int temp=0;
 46 
 47     while ( low<high )
 48     {
 49         //浠庤〃鐨勪袱绔氦鏇跨殑鍚戜腑闂存壂鎻?/span>
 50         while (low<high && SortData[high]>=tmpData)
 51         {
 52             high--;
 53         }
 54         //灝嗘瘮鏋㈣醬璁板綍灝忕殑璁板綍縐誨埌浣庣
 55         SortData[low] =SortData[high];
 56 
 57         while (low<high && SortData[low]<=tmpData)
 58         {
 59             low++;
 60         }
 61         //灝嗘瘮鏋㈣醬璁板綍澶х殑璁板綍縐誨埌楂樼
 62         SortData[high] =SortData[low];
 63     }
 64     //鏋㈣醬璁板綍鍒頒綅
 65     SortData[low] =tmpData;
 66 
 67     return low;//榪斿洖鏋㈣醬鎵鍦ㄤ綅緗?/span>
 68 }
 69 
 70 void QuickSortData(int SortData[], int low, int high)
 71 {
 72     int offset;
 73 
 74     if ( low<high )
 75     {
 76         offset =Partition(SortData, low, high);
 77         QuickSortData(SortData, low, offset-1);
 78         QuickSortData(SortData, offset+1, high);
 79     }
 80 }
 81 
 82 /*/////////////////////////////////////////////////////////////////////////
 83 浠ヤ笅涓烘彃鍏ユ帓搴?br> 84 /////////////////////////////////////////////////////////////////////////*/
 85 /*
 86 鐩存帴鎻掑叆鎺掑簭
 87 綆楁硶錛氱粡榪噄-1閬嶅鐞嗗悗錛孡[1..i-1]宸辨帓濂藉簭銆傜i閬嶅鐞嗕粎灝哃[i]鎻掑叆L[1..i-1]鐨勯傚綋浣嶇疆錛?br> 88 浣垮緱L[1..i]鍙堟槸鎺掑ソ搴忕殑搴忓垪銆傝杈懼埌榪欎釜鐩殑錛屾垜浠彲浠ョ敤欏哄簭姣旇緝鐨勬柟娉曘?br> 89 棣栧厛姣旇緝L[i]鍜孡[i-1]錛屽鏋淟[i-1]<=L[i]錛屽垯L[1..i]宸叉帓濂藉簭錛岀i閬嶅鐞嗗氨緇撴潫浜?
 90 鍚﹀垯浜ゆ崲L[i]涓嶭[i-1]鐨勪綅緗紝緇х畫姣旇緝L[i-1]鍜孡[i-2]錛岀洿鍒版壘鍒版煇涓涓綅緗甹(1≤j≤i-1)錛?br> 91 浣垮緱L[j] ≤L[j+1]鏃朵負姝?br> 92 浼樼偣:縐誨姩鍏冪礌嬈℃暟灝戯紝鍙渶瑕佷竴涓緟鍔╃┖闂?br> 93 鏃墮棿澶嶆潅搴*n
 94 褰撳緟鎺掑簭璁板綍鐨勬暟閲弉寰堝皬鏃訛紝榪欐槸涓縐嶅緢濂界殑鎺掑簭鏂規硶銆備絾鏄痭寰堝ぇ鏃訛紝鍒欎笉閫傚悎
 95 */
 96 void InsertSortData(int SortData[], int Length)
 97 {
 98     int tmpData =0;
 99     int i=0;
100     int j=0;
101 
102     for(i=1; i<Length; i++)
103     {
104         if ( SortData[i] <SortData[i-1])
105         {
106             tmpData =SortData[i];
107             //鏁版嵁寰鍚庣Щ鍔?/span>
108             for (j=i-1; j>=0 && tmpData<SortData[j]; j--)
109             {
110                 SortData[j+1=SortData[j];
111             }
112             //灝嗘暟鎹彃鍏ュ埌j+1浣嶇疆
113             SortData[j+1=tmpData;
114         }
115     }
116 
117     return;
118 }
119 
120 /*
121 鎷嗗崐鎻掑叆鎺掑簭鎵闇瑕佺殑杈呭姪絀洪棿鍜岀洿鎺ユ彃鍏ユ帓搴忕浉鍚岋紝浠庢椂闂翠笂姣旇緝錛屾姌鍗婃彃鍏ユ帓搴忎粎鍑忓皯浜嗗叧閿瓧闂寸殑姣旇緝嬈℃暟錛岃岃褰曠殑縐誨姩嬈℃暟涓嶅彉銆?br>122 鍥犱負鏃墮棿澶嶆潅搴︿粛涓簄*n
123 */
124 void BInsertSortData(int SortData[], int Length)
125 {
126     int tmpData =0;
127     int i=0;
128     int j=0;
129     int low;
130     int high;
131     int middle;
132 
133     for(i=1; i<Length; i++)
134     {
135         tmpData =SortData[i];
136         low =0;
137         high =i-1;
138         //鍦╮[low..high]涓姌鍗婃煡鎵炬湁搴忔彃鍏ョ殑浣嶇疆
139         while ( low<=high )
140         {
141             middle =(low+high)/2;
142             if ( tmpData <SortData[middle] )
143             {
144                 high =middle-1;
145             }
146             else
147             {
148                 low =middle+1;
149             }
150         }
151         //璁板綍鍚庣Щ
152         for (j=i-1; j>=high+1; j--)
153         {
154             SortData[j+1=SortData[j];
155         }
156         SortData[high+1=tmpData;
157     }
158 
159     return;
160 }
161 
162 
163 //////////////////////////////////////////////////////////////////////////
164 
165 /*
166 綆鍗曢夋嫨鎺掑簭
167 綆楁硶錛氶鍏堟壘鍒版暟鎹竻鍗曚腑鐨勬渶灝忕殑鏁版嵁錛岀劧鍚庡皢榪欎釜鏁版嵁鍚岀涓涓暟鎹氦鎹綅緗紱鎺ヤ笅鏉ユ壘絎簩灝忕殑鏁版嵁錛屽啀灝嗗叾鍚岀浜屼釜鏁版嵁浜ゆ崲浣嶇疆錛屼互姝ょ被鎺ㄣ?br>168 鎵闇縐誨姩鐨勬搷浣滄鏁版渶灝戜負0,,鏈澶т負3(n-1)
169 鐒惰屾棤璁鴻褰曠殑鍒濆鎺掑垪濡備綍錛岄渶瑕佹瘮杈冪殑嬈℃暟鐩稿悓n(n-1)/2 澶嶆潅搴︿負n*n
170 */
171 void SelectSortData(int SortData[], int Length)
172 {
173     int tmpData;
174     int offset =0;
175     int j=0;
176 
177     for (int i=0; i<Length-1; i++)
178     {
179         offset =0;
180         tmpData =SortData[i];
181         for (j=i+1; j<Length; j++)
182         {
183             if ( tmpData>SortData[j] )
184             {
185                 tmpData =SortData[j];
186                 offset =j;
187             }
188         }
189 
190         if( offset >i)
191         {
192             SortData[offset] =SortData[i];
193             SortData[i] =tmpData;
194         }
195     }
196 
197     return;
198 }
199 
200 int main()
201 {
202     //int Buffer[] ={1,2,3,4,5,6};
203     int Buffer[] ={6,5,4,3,2,1};
204 
205     QuickSortData(Buffer,05);
206 
207     for (int i=0; i<6; i++)
208     {
209         cout<<Buffer[i]<<" ";
210     }
211     cout<<endl;
212 
213     return 0;
214 }
215 http://www.shnenglu.com/Files/bujiwu/SortData.rar


bujiwu 2008-10-25 23:53 鍙戣〃璇勮
]]>
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            亚洲欧美日韩爽爽影院| 久久人人爽人人爽爽久久| 亚洲国产精品小视频| 久久久欧美一区二区| 黄色在线一区| 欧美mv日韩mv国产网站| 麻豆91精品| 在线视频欧美一区| 亚洲线精品一区二区三区八戒| 国产精品亚洲一区| 久久婷婷色综合| 亚洲欧美日韩国产综合| 精久久久久久久久久久| 亚洲欧美日韩一区在线| 欧美一区二区在线| 一区二区三区视频观看| 亚洲欧美久久久| 亚洲欧洲日韩综合二区| 亚洲综合色婷婷| 亚洲精品一区二区三区99| 欧美一区二区三区播放老司机| 亚洲成在人线av| 国产在线观看一区| 欧美成年人视频网站欧美| 欧美精品福利| 久久国产精品99久久久久久老狼 | 国产主播一区二区三区四区| 模特精品裸拍一区| 欧美性做爰毛片| 久久综合999| 国产精品豆花视频| 欧美二区在线播放| 国产欧美日韩视频在线观看| 欧美激情一区二区三区不卡| 国产乱码精品一区二区三区五月婷| 免费中文字幕日韩欧美| 国产精品美女久久久久久2018| 模特精品在线| 国产三级欧美三级| aa国产精品| 亚洲人成人一区二区在线观看| 亚洲一区高清| 9色porny自拍视频一区二区| 久久国产加勒比精品无码| 亚洲无玛一区| 欧美黑人在线观看| 免费观看一级特黄欧美大片| 国产精品尤物| 一区二区三区欧美日韩| 亚洲精品久久久久久久久久久久久| 香蕉久久久久久久av网站| 亚洲一区二区三区四区中文| 欧美gay视频| 免费观看成人鲁鲁鲁鲁鲁视频 | 欧美日产国产成人免费图片| 老司机午夜精品视频在线观看| 国产精品一区=区| 99精品视频一区| 一本一本a久久| 欧美精品国产精品| 亚洲高清在线精品| 亚洲国产精品一区二区久| 久久精品国产精品| 久久嫩草精品久久久精品| 国产婷婷色综合av蜜臀av| 亚洲综合精品自拍| 午夜精品美女久久久久av福利| 欧美午夜不卡在线观看免费 | 亚洲一区二区三区在线播放| 亚洲一区二区在线免费观看视频| 欧美日韩亚洲91| 亚洲看片网站| 亚洲一区二区网站| 国产精品网站一区| 西瓜成人精品人成网站| 久久精品女人| 在线精品观看| 欧美国产亚洲另类动漫| 亚洲免费电影在线观看| 午夜电影亚洲| 狠狠色噜噜狠狠色综合久| 久久精品夜色噜噜亚洲aⅴ| 免费日韩成人| 一区二区高清在线| 国产精品免费网站在线观看| 亚洲永久免费av| 美女精品国产| 中文精品99久久国产香蕉| 国产精品久久久久久久久动漫| 欧美一区二区大片| 亚洲国产精品久久91精品| 亚洲校园激情| 激情久久综艺| 欧美日韩成人在线播放| 欧美一区二区| 亚洲欧洲综合另类| 亚洲欧美一区二区精品久久久| 韩国精品在线观看| 欧美日产国产成人免费图片| 校园激情久久| 亚洲激情第一页| 久久国产手机看片| 亚洲裸体在线观看| 国产麻豆91精品| 欧美二区不卡| 久久国产视频网| 亚洲九九精品| 久久躁狠狠躁夜夜爽| 中文精品99久久国产香蕉| 狠狠久久婷婷| 国产精品久久久爽爽爽麻豆色哟哟| 久久精品国产精品亚洲精品| 一本色道久久综合一区| 欧美1区视频| 久久国产精品久久久久久电车| 亚洲九九爱视频| 国产亚洲一区二区三区| 欧美视频一区在线观看| 美腿丝袜亚洲色图| 欧美亚洲综合久久| 亚洲午夜免费视频| 亚洲欧洲一区二区天堂久久| 老司机67194精品线观看| 性亚洲最疯狂xxxx高清| 99精品福利视频| 91久久精品国产91久久性色| 国产日韩精品视频一区二区三区| 欧美精品一区二区三区在线播放| 久久久www成人免费毛片麻豆| 亚洲一区二区在| 中日韩高清电影网| 日韩网站在线观看| 亚洲精品久久久久久下一站| 欧美激情精品久久久久久免费印度 | 亚洲综合视频一区| 亚洲精品国久久99热| 亚洲第一精品电影| 在线观看91精品国产麻豆| 国产一区二区在线免费观看 | 欧美午夜片在线免费观看| 欧美成人精品三级在线观看| 久久久亚洲成人| 久久夜色精品国产亚洲aⅴ| 久久久久看片| 免费美女久久99| 免费视频一区| 欧美69视频| 欧美日韩黄色大片| 欧美丝袜第一区| 国产精品视频| 国产亚洲欧美日韩精品| 国产三区二区一区久久| 国产一区二区三区久久| 影音先锋久久精品| 亚洲国产精品久久久久| 亚洲蜜桃精久久久久久久| 99www免费人成精品| 亚洲午夜精品| 欧美在线观看网址综合| 久久免费国产| 亚洲国产成人精品女人久久久 | 久久久久国产精品午夜一区| 久久夜色精品国产欧美乱极品| 老色鬼久久亚洲一区二区| 欧美华人在线视频| 国产精品久久毛片a| 国内精品久久久久久久影视蜜臀| 一区精品在线| 一区二区三区国产精华| 亚洲愉拍自拍另类高清精品| 久久精品日韩| 亚洲黄色高清| 午夜国产精品视频| 女女同性女同一区二区三区91| 欧美欧美天天天天操| 国产精品入口| 亚洲国产日韩在线| 亚洲综合社区| 欧美成人免费在线视频| 一区二区动漫| 麻豆精品传媒视频| 国产精品欧美久久| 亚洲风情在线资源站| 午夜精品久久久久久| 欧美成人亚洲| 午夜视频久久久久久| 欧美成人精品不卡视频在线观看 | 国产精品大片wwwwww| 精久久久久久| 午夜精品久久久久久| 亚洲激情视频在线播放| 欧美在线视频在线播放完整版免费观看 | 国产精品免费久久久久久| 在线观看成人网| 午夜精品福利在线观看| 亚洲人成网站色ww在线| 久久久久久久高潮| 国产精品视频网| 亚洲视频1区| 亚洲国产另类久久久精品极度|