Foundation: Comparison Counting Sort

本文探讨了排序算法中的基数计数排序方法,深入解析其原理和应用,适合对基础算法感兴趣的读者。
摘要由CSDN通过智能技术生成
#include "distribution_counting.h"

/* [Distribution Counting Sort] 
 * First used with radix sorting by H.Seward, 1954.
 * Then published with "Mathsort" by W.Feurzeig, CACM 3 (1960), 601
 */


static int *counting_table = NULL;
static int cur_table_len = 0;

static int
create_counting_table(int cnt)
{
	F_S();

	counting_table = (int*)malloc(sizeof(int) * cnt);
	if(counting_table == NULL) {
		debug("malloc failed. [%s] \r\n", __FUNCTION__);
		return 0;
	}

	cur_table_len = cnt;

	F_E();

	return 1;
}

void
free_counting_table(void)
{
	F_S();

	if (counting_table == NULL) return;
	free(counting_table);
	counting_table = NULL;
	cur_table_len = 0;

	F_E();
}


/* we guess all the items located in [@min, @max],
 * and do the counting for sorting.
 */
int* 
do_distribution_counting_sort(void* src, int src_sz, int item_cnt, int min, int max, void *out, 
							  GET_ITEM_FUNC get_item, SE
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值