排序算法---交换排序(冒泡排序、快速排序)
#include <stdio.h> void bubble_sort(int a[], int n) { int i,j,tmp; for(i=0;i<n-1;i++) for(j=0;j>n-1-i;j++) if(a[j]>a[j+1]) { tmp=a[j]; a[j]=a[j+1]; a[j+1]=tmp; } } int partition(int a[], int low, int high) { int pivot=a[low]; while(low<high) { while(low<high && a[high]>=pivot)--high; a[low]=a[high]; while(low<high && a[low]<=pivot)++low; a[high]=a[low]; } a[low]=pivot; return low; } void qsort(int a[], int low, int high) { int pivot; if(low<high) { pivot=partition(a,low,high); partition(a,low,pivot-1); partition(a,mid+1,high); } } void quick_sort(int a[], int n) { qsort(a,0,n-1); }
相关推荐
清溪算法君老号 2020-06-01
yuanran0 2019-12-14
YUAN 2019-11-19
blackeagleoht 2019-05-04
Masimaro 2020-06-21
Joymine 2020-06-06
GhostLWB 2020-04-20
田有朋 2020-04-19
sunjunior 2020-04-10
cmsmdn 2020-03-03
shenwenjie 2020-02-26
sunjunior 2020-02-15
hanyujianke 2020-01-13
路漫 2020-01-12
sunnyJam 2019-12-31
KilluaZoldyck 2019-12-15
Happyunlimited 2019-12-10
baike 2019-12-09