选择类排序:选择排序和堆排序
来源:互联网 发布:ubuntu配置jdk 编辑:程序博客网 时间:2024/06/03 18:17
选择排序
void select_sort(int *arr,int size){ int tmp=0; for(int i=0;i<size-1;i++) { for(int j=i+1;j<size;j++) { if(arr[j]<arr[i]) { tmp=arr[j]; arr[j]=arr[i]; arr[i]=tmp; } } }}
堆排序
void AdjustDown(int *arr,int size,int root){ int parent=root; //左孩子 int child=root*2+1; while(child<size){if(child+1<size&&arr[child+1]>arr[child]) child+=1; if(arr[child]>arr[parent]) { std::swap(arr[parent],arr[child]); parent=child; child=parent*2+1; } else break; }}void heap_sort(int *arr,int size){ //创建堆 for(int i=(size-2)>>1;i>=0;i--) { AdjustDown(arr,size,i); } //排序 for(int j=size-1;j>0;j--) { std::swap(arr[0],arr[j]); AdjustDown(arr,j,0); }}
阅读全文
0 0
- 选择类排序:选择排序,堆排序
- 选择类排序:选择排序和堆排序
- 选择排序和堆排序
- 选择排序和堆排序
- 选择排序和堆排序
- 选择排序和堆排序
- 选择排序和堆排序
- 选择排序和堆排序
- 选择排序和堆排序
- 【选择排序】和【堆排序】
- 选择排序和堆排序
- 选择排序和堆排序
- 选择类排序-堆排序
- 选择类排序---堆排序
- 排序-->选择排序(选择排序&&堆排序)
- 选择类-----堆排序
- 选择排序--堆排序
- 选择排序:堆排序
- BeanUtil解读
- 初识向量的点乘,叉乘,函数的弧度转角度,以及弦值转弧度!
- Android隐藏app桌面图标
- HDU---2108
- OAuth和OpenID区别
- 选择类排序:选择排序和堆排序
- rsync 服务器搭建
- 数据库学习纪要(二):hive-2
- 字符设备驱动程序之misc_dev方式注册字符设备
- Spring Bean的生命周期
- 初识HBase
- fgets与fgetc函数
- table标记
- https实践之 抓包分析流程