交換排序(氣泡排序與快速排序)

2022-09-16 14:54:08 字數 1355 閱讀 9170

1

//氣泡排序

2void bubblesort(int array, int

n) 316

}17}18 }

快速排序動態圖

1

//快速排序01

2void insertsort(int array, int left,int

right)

315 swap(array[i], array[j]);//

將比樞軸移小的資料移至低端

16while (i < j && array[i] <=temp)

1720 swap(array[i], array[j]);//

將比樞軸移大的資料移至搞端21}

22 insertsort(array, left, i-1);//

對低子表遞迴

23 insertsort(array, i+1, right);//

對高子表遞迴

24 }

1

//快速排序02

2void insertsort(int array, int left,int

right)315

while (i < j && array[i] <=temp)

1619 swap(array[i], array[j]);//

左側比樞軸大的資料與右側比樞軸小的資料交換位置20}

21 swap(array[left], array[i]);//

將左側樞軸交換至中間合適位置

22 insertsort(array, left, i-1);//

對低子表遞迴

23 insertsort(array, i+1, right);//

對高子表遞迴

氣泡排序時間複雜度為o(n2);

交換排序 氣泡排序與快速排序

氣泡排序 基本思想 每次比較兩個相鄰的元素,如果它們的順序錯誤就把它們交換過來。核心 for i 1 i n 1 i 快速排序 交換 快速排序 include int a 101 n void quicksort int left,int right 將基準數歸位 a left a i a i te...

交換排序 氣泡排序與快速排序

氣泡排序 廢話不多說,直接上 注意2中冒泡方法的不同。user sqtds date 13 1 15 time 下午3 03 public class bubble public static void swap int array int left int right public static ...

交換排序 氣泡排序,快速排序

交換排序 氣泡排序,快速排序 執行環境 vs2010 include include include include define ok 1 define true 1 define false 0 define maxsize 50 typedef struct redtype typedef s...