标签:++ style 技术 src col while ima oid bubuko
1.选择排序
for(i=0;i<n-1;i++){//n-1趟 int k=i;//令第一个数为最小值 for(j=i+1;j<n;j++){ if(a[k]>a[j]){ t = a[k]; a[k] = a[j]; a[j] = t; } } }
2.冒泡排序
for(i=0;i<n-1;i++){//n-1趟冒泡 for(j=0;j<n-i-1;j++){ if(a[j]>a[j+1]){ t = a[j]; a[j] = a[j+1]; a[j+1] = t; } } }
3.快速排序(排序不稳定)
void quick_sort(int a[],int low,int high){ int pivot = a[low]; int i = low+1; int j = high;int temp; while(i<j){ while((i<j)&&pivot<=a[j]){ --j; } while((i<j)&&pivot>=a[i]){ ++i; } if(i<j){ temp = a[i]; a[i] = a[j]; a[j] = temp; } } if(a[low]>a[j]){ temp = a[low]; a[low] = a[j]; a[j] = temp; } if(i-low>1) quick_sort(a,low,i-1); if(high-j>1) quick_sort(a,j+1,high); }
标签:++ style 技术 src col while ima oid bubuko
原文地址:https://www.cnblogs.com/zoulingjin/p/9349690.html