当前位置:网站首页>Bucket sorting ← C language implementation
Bucket sorting ← C language implementation
2022-04-21 10:44:00 【hnjzsyjyj】
【 The idea of bucket sorting 】
- If the value to be sorted is in a limited range ( integer ) when , A finite number of ordered barrels can be designed , Bucket number is the value to be sorted .
- after , Load the values to be sorted into the corresponding ordered bucket in turn ( Duplicate values are loaded into the corresponding bucket ), then Output the value of each bucket in sequence , You get an ordered sequence .

【C The language code 】
#include <stdio.h>
#include <math.h>
const int maxn=500;
int t[maxn];
int main() {
int n;
scanf("%d",&n);
int x; //x is less than maxn
int i,j;
for(i=1; i<=n; i++) {
scanf("%d",&x);
t[x]++;
}
for(j=1; j<=maxn; j++) {
while(t[j]>0) {
printf("%d ",j);
t[j]--;
}
}
return 0;
}
/*
in:
10
20 40 32 67 40 20 89 300 400 15
out:
15 20 20 32 40 40 67 89 300 400
*/
版权声明
本文为[hnjzsyjyj]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204211039133933.html
边栏推荐
- 本地IP地址使用域名访问
- What is the future development prospect of automated operation and maintenance platform?
- Better than SQL, another domestic database language was born
- 【天梯赛】L3-005 垃圾箱分布(堆优化版dijkstra)
- What happens when you run the NPM install command?
- Six practices of Windows operating system security attack and defense
- Vulnhub PRIME: 1
- 泛型note
- Pytoch learning notes (3) torch Autograd, logistic regression model, training
- Pytorch梯度检查 torch.autograd.gradcheck
猜你喜欢

Digital Economy & Green Innovation matching: Green Patent matching data of digital finance enterprises of 3169 companies in China, 2011-2019

24 pictures to conquer border image

Enter the welcome interface when idea and pycharm are started

Convbert: improving Bert with span based dynamic revolution

2022 information and future preparation 1 new online judge 1112: plane segmentation

“空气洗”再迎迭代,模仿者又有了新目标

力扣(LeetCode)110. 平衡二叉树(2022.04.20)

The most easy to understand dependency injection and control inversion

24张图攻克border-image

Android learning ① various reasons why Android cannot connect to MySQL database and Solutions
随机推荐
【pytorch】实现1对多的IOU计算技巧
Go uses channel for synchronization (channel 1)
伦敦金在哪里开户安全?
shell脚本修改文件名和权限
L1-045 cosmic invincible greeting (5 points)
TypeError: The view function did not return a valid response. The function either returned None 的解决
Oracle密码过期问题,设置永不过期
你不知道的 parseInt?
Use of go function
DFS of vigorously flying brick (creation of tree)
Microsoft updates the verifier application for Android / IOS to support the generation of more secure strong passwords
What happens when you run the NPM install command?
GO语言反射机制
2022 information and future preparation 1 new online judge 1112: plane segmentation
O2OA二次开发-使用开源平台搭建完整OA(3)-开发企业报销审批
Recursive function C language question type
Enter the welcome interface when idea and pycharm are started
Better than SQL, another domestic database language was born
Release announcement of HMS core version 6.4.0
MKL and vs2019 configuration method