计数排序
来源:互联网 发布:java项目目录结构 编辑:程序博客网 时间:2024/06/07 11:10
#include<stdio.h>#include<string.h>int c[11]={0};void count_sort(int *a,int *b,int len);int main(){ int arr[]={1,2,3,4,5,6,7,8,9,10}; int count = sizeof(arr) /sizeof(int);//获取长度 printf("count %d\n",count); int b[count]; count_sort(arr,b,count); for(int i=0;i<count;i++) printf("%d ",arr[i]); return 0;}void count_sort(int *a,int *b,int len){ for(int j=0;j<len;j++) c[a[j]] = c[a[j]] + 1;//记录各个数字的个数 for(int i=1;i<len;i++) c[i] = c[i] + c[i-1];//统计后一个数都大于多少数字 for(int j=len-1;j>=0;j--) { b[ c[ a[j] ] ]= a[j];//c有几个,a对应值就在b的第几个 c[j] = c[j] -1;//输出一个,一个数大于多少数就要减小 }}
阅读全文
0 0
- 计数排序
- 计数排序
- 计数排序
- 计数排序
- 计数排序
- 计数排序
- 计数排序
- 计数排序
- 计数排序
- 计数排序
- 计数排序
- 计数排序
- 计数排序
- 计数排序
- 计数排序
- 计数排序
- 计数排序
- 计数排序
- Java接口回顾
- CSS样式引入方式和部分CSS样式的设置
- 树莓派使用ubuntu mate
- 闭包的运用-点赞-计数器
- SprintBoot学习笔记004(dao层jpa接口)
- 计数排序
- 九度OJ——1201二叉排序树
- Tensorflow基础:模型持久化
- 日期+序列构建系统唯一序列号(二)
- QT(1):空工程建立程序方式与文本建立程序方式的运行
- flask 的url_for
- 大数据算法面试题
- inline关键字
- 创建一个类Student