九章排序ppt課件_第1頁(yè)
九章排序ppt課件_第2頁(yè)
九章排序ppt課件_第3頁(yè)
九章排序ppt課件_第4頁(yè)
九章排序ppt課件_第5頁(yè)
已閱讀5頁(yè),還剩60頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、各趟排序結(jié)果各趟排序結(jié)果0 1 2 3 4 50 1 2 3 4 5 temp250 1 2 3 4 5 temp4925*0 1 2 3 4 50 1 2 3 4 5 temp160 1 2 3 4 5 temp0816490 1 2 3 4 50 1 2 3 4 5 temp0 1 2 3 4 5 temp完成2525*0 1 2 3 4 50 1 2 3 4 5 temp0 1 2 3 4 5 temp21 Vectorj = temp; 111122142221nininnniRMNnnniKCN/)()( ,/)(22 while ( Left = Right ) int middl

2、e = ( Left + Right )/2; if ( temp = Left; k- ) Vectork+1 = Vectork; VectorLeft = temp; 1122log1logninnin例:例:99,14,28,31,2,7,46,70,62,180,30,82,170,5,90 1 2 3 4 5492516084925*0821252125*160 1 2 3 4 5491625*0821250 1 2 3 4 5序序 for ( int j = i; j = gap; j -= gap ) if ( temp Vectorj-gap ) Vectorj = Vect

3、orj-gap; else break; Vectorj = temp; gap = ( int ) ( gap / 2 ); 0 1 2 3 4 50 1 2 3 4 5 Swap ( Vectorj-1, Vectorj ); /交換 exchange = 1; /標(biāo)志置為1,有交換 pass+; 11111233121nininninRMNnninKCN)()()()(直到一切的對(duì)象都排在相應(yīng)位置上為止直到一切的對(duì)象都排在相應(yīng)位置上為止。QuickSort ( List ) if ( List的長(zhǎng)度大于的長(zhǎng)度大于1) 將序列將序列List劃分為兩個(gè)子序列劃分為兩個(gè)子序列 LeftList

4、 和和 Right List; QuickSort ( LeftList );QuickSort ( RightList ); 將兩個(gè)子序列將兩個(gè)子序列 LeftList 和和 RightList 合并為一個(gè)序列合并為一個(gè)序列List; 快速排序的算法思想分治法分 難合并容易初始關(guān)鍵字:28 19 27 48 56 12 10 25 20 50完成第一趟后20 19 27 25 10 12 28 56 48 50完成第二趟12 19 10 20 25 27 28 50 48 56完成第三趟10 12 19 20 25 27 28 50 48 56int dataList : Partition

5、 (int s, int t ) int x, i, j; x=Vectors; i=s; j=t; while ( i j) while ( ( i =x) j=j-1; if (ij) ai=aj; while ( ( i j) & (Vectori=x) i=i+1; if (ij) aj=ai; Vectori =x; return i;序方法還要慢。序方法還要慢。2121211nnninni)()(0 1 2 3 4 5最小者最小者 08交換交換21,08最小者最小者 16交換交換25,16最小者最小者 21交換交換49,210 1 2 3 4 5結(jié)果結(jié)果最小者最小者 25*無(wú)交換無(wú)

6、交換最小者最小者 25無(wú)交換無(wú)交換各趟排序后的結(jié)果各趟排序后的結(jié)果012345025431012345025431template void MaxHeap :FilterDown ( const int i, const int EndOfHeap ) int current = i; int child = 2*i+1; Type temp = heapi; while ( child = EndOfHeap ) /最后位置最后位置 if ( child +1 EndOfHeap & heapchild = heapchild ) break; /temp排序碼大排序碼大, 不做調(diào)整不做調(diào)

7、整 else heapcurrent = heapchild; /大子女上移 current = child; /向下繼續(xù)調(diào)整 child = 2*child+1; heapcurrent = temp; /回放到適宜位置012345025431012345025431012345025431012345025431012345025431 mergedList.Vectork = Vectori; i+; k+; else mergedList.Vectork = Vectorj; j+; k+; if ( i = mid ) for ( int n1 = k, n2 = i; n2 = m

8、id; n1+, n2+ ) mergedList.Vectorn1 = Vectorn2; else for ( int n1 = k, n2 = j; n2 = right; n1+, n2+) mergedList.Vectorn1 = Vectorn2;template void datalist :MergePass ( dataList & mergedList, const int len ) int i = 0; while (i+2*len = CurrentSize-1) merge(mergedList, i, i+len-1, i+2*len-1); i += 2 * len; /循環(huán)兩兩歸并循環(huán)兩兩歸并 if ( i+len = CurrentS

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論