当前位置:网站首页>Sort 5-count sort
Sort 5-count sort
2022-07-28 16:31:00 【World_ living】
Catalog
Preface

One 、 Count sorting
thought : Counting sorting is also called pigeon nest principle , It is an application of the deformation of hash table direct addressing method . Operation steps :
- Count the number of identical elements
- According to the statistical results, the sequence is recycled into the original sequence
Absolute mapping :
details :
(1): When the maximum value in the array is large , And the minimum value in the array is also large , So we open up B Space , There will be a lot of waste .
So relative mapping comes :
Code :( Several details should be handled carefully )
void CountSort(int* a,int n)
{
// Select the maximum value , minimum value
int i = 0,min = a[0],max = a[0];
for(i = 0;i < n;i++)
{
if(a[i] > max)
max = a[i];
if(a[i] < min)
min = a[i];
}
int range = max - min + 1;
int* count = (int*)malloc(sizeof(int) * range);
memset(count,0,sizeof(int) * range);
// Count
for(i = 0;i < n;i++)
{
count[a[i] -min]++;
}
int j = 0;
// Sort
for(i = 0;i < range;i++)
{
while(count[i]--)
{
a[j++] = i + min;
}
}
}
summary :
- Count sort can only be used for integer sort
- The efficiency of counting sorting in data range set is high , Limited application scenarios
- Time complexity :O(N~range)
- Spatial complexity :O(range)
- stability : Stable
See you next time .
边栏推荐
猜你喜欢

软件问题修复跟踪系统实战开发教程(上篇)

在abaqus中使用PyQt设计GUI

A good start

QT打包

mysql 查看事件状态语句和修改办法

Practical development tutorial of software problem repair tracking system (Part 1)

About standard IO buffers

食品安全 | 这两类瓜果宜改善便秘 孕妇人群尤其建议

Thoughts on solving the pop-up of malicious computer advertisements

排序3-选择排序与归并排序(递归实现+非递归实现)
随机推荐
PHP 图片上传
后台弹出layer提示
2021-04-02
About standard IO buffers
PHP获取小程序码,小程序带参数跳转
Is MySQL query limit 1000,10 as fast as limit 10? If I want to page, what should I do?
Baidu editor ueeditor, when editing too much content, the toolbar is not visible, which is not convenient for editing or uploading problems
R language ggplot2 visually draws line plots, and uses gghighlight package to highlight the lines that meet the combination judgment conditions in the line graphs (satisfies both condition a and b)
百度编辑器ueditor,编辑内容过多时,工具栏不可见,不方便编辑或上传问题
c语言编程当中两个!!的作用
Telecommuting can be easily realized in only three steps
Qt学习之信号和槽机制
Two of C language programming!! Role of
PHP计算坐标距离
使用js直传oss阿里云存储文件,解决大文件上传服务器限制
HDU1847解题思路
PHP mb_ Substr Chinese garbled code
Record doc
关于MIT6.828_HW9_barriers xv6 homework9的一些问题
1. Simple command line connection to database