CoutingSort
#include <stdio.h>
#include <stdlib.h>
void CountingSort(int A[], int B[], int k,int n)
{
int * C;
C=(int *)calloc(k,sizeof(int));
for(int i=0;i<n; i++)
{
C[A[i]]++;
}
for(i=1; i<k; i++)
{
C[i]+=C[i-1];
}
for(i=n-1; i>=0; --i)
{
B[C[A[i]]-1]=A[i];
C[A[i]]--;
}
free(C);
}
int main()
{
int A[]={1,3,3,2,9,6,7,8,5,6,4,3,7};
int k=10;
int B[13];
CountingSort(A,B,k,13);
printf("排序后的数组\n");
for(int i=0;i<13;i++)
{
printf("%d\t",B[i]);
}
}
注意:
1.数组初始化
int * p=(int *) calloc(k,size(int)); 会对内存空间初始化为0、
int * p=(int *) malloc(k*size(int));不会对内存空间初始化。
2.注意数组下标
分享到:
相关推荐
CountingSort为AlgorithmMan中的计数排序演示工具(这是可执行文件;需要.net 4.0支持;非源代码)。 原文:C#算法设计排序篇之08-计数排序(附带动画演示程序) 链接:...
排序算法 排序算法_基于C语言实现的排序算法之CountingSort实现
var countingSort = require ( './countingSort.js' ) ; // Construct input [0, 5], therefore an array of size 6 is needed // for the temporary storage space. var input = [ 2 , 5 , 3 , 0 , 2 , 3 , 0 , 3 ...
伪代码和算法介绍在此:http://www.algorithmist.com/index.php/Counting_sort,本程序是 根据这个伪代码编写的源代码
计数排序(Counting Sort) 循环排序(Cycle Sort) 双重排序(Double Sort) 荷兰国旗排序(Dutch National Flag Sort) 交换排序(Exchange Sort) 外部排序(External Sort) 侏儒排序(Gnome Sort) 堆排序...
经典的排序算法C#源码,包括: 经典排序算法 - 快速排序Quick sort 经典排序算法 - 桶排序Bucket sort 经典排序算法 - 插入排序Insertion sort 经典排序算法 - 基数排序...经典排序算法 - 计数排序Counting sort
countingSort 方法实现了计数排序算法。首先,我们遍历一遍原数组,找出其中的最大值,以确定计数数组的大小。然后,创建计数数组 count,并将每个元素的出现次数记录在计数数组中。接下来,根据计数数组中的元素...
计数排序(Counting Sort) 基数排序(Radix Sort) 桶排序(Bucket Sort) 深度优先搜索(Depth-First Search, DFS) 广度优先搜索(Breadth-First Search, BFS) 二分查找(Binary Search) 线性查找(Linear ...
1.7 CountingSort: 假设数据分布在0到k之间的。对于每个输入x,确定出小于x的数的个数。假设小于x的数有17个,那么x就应该在第18个输出位置。 1. 8 Radix sort(基数排序):从最低位开始,每位采用稳定的排序算法...
counting sort implemented in c++
| _O(n)_ ~ _O(n^2)_ | _O(n)_ | Medium || Bit Manipulation, Counting Sort, Pruning| 342 | [Power of Four](https://leetcode.com/problems/power-of-four/) | [C++](./C++/power-of-four.cpp) [Python](./...
计数排序计数排序是一种基于特定范围内的键的排序技术。 它通过计算具有不同键值的对象数量来工作(类似于哈希)。
8.2 Counting sort 194 8.3 Radix sort 197 8.4 Bucket sort 200 9 Medians and Order Statistics 213 9.1 Minimum and maximum 214 9.2 Selection in expected linear time 215 9.3 Selection in worst-case linear...
计数排序并行openmp Esterepositórioabriga实施工具会按顺序对序数进行排序。 Esses algoritmos foram desenvolvidos no Programme da Disciplina deProgramaçãoParalela e Multicore do curso deCiê...
void CountingSort(int t[],int n,int r[],int e,int q[]) { int i; //计数排序 for( i=0;i;i++) q[i]=0;//把数组元素全部赋初值为0 for( i=0;i;i++) q[t[i]]+=1;//判断累计相同等待时间的个数 q[t[i]]=q[t[i]...
8.2 Counting sort 194 8.3 Radix sort 197 8.4 Bucket sort 200 9 Medians and Order Statistics 213 9.1 Minimum and maximum 214 9.2 Selection in expected linear time 215 9.3 Selection in worst-case linear...
8.2 Counting sort 194 8.3 Radix sort 197 8.4 Bucket sort 200 9 Medians and Order Statistics 213 9.1 Minimum and maximum 214 9.2 Selection in expected linear time 215 9.3 Selection in worst-case linear...
8.1 Lower bounds for sorting 191 8.2 Counting sort 194 8.3 Radix sort 197 8.4 Bucket sort 200 9 Medians and Order Statistics 213 9.1 Minimum and maximum 214 9.2 Selection in expected linear time 215 ...
8.2 Counting sort i68 8.3 Radix sort 170 8.4 Bucket sort 174 9 Medians and Order Statistics 183 9.1 Minimum and maximum 184 9.2 Selection in expected linear time 185 9.3 Selection in worst-case linear...