计数排序 C语言实现版

#include <stdio.h>

void countSort(int A[],int B[],int length){
	int k = 10,i,j;
	int help[10];
	for(i=0;i<k;i++){
		help[i] = 0;
	}
	for(i=0;i<length;i++){
		help[A[i]]++;
	}
	for(j = 1;j<k;j++){
		help[j]+=help[j-1];
	}
	for(i = 0;i<length;i++){
		B[help[A[i]]-1] = A[i];
		help[A[i]]--;
	}
	for(i = 0;i<length;i++){
		printf("%d\t",B[i]);
	}
	printf("\n");
}

int main(){
	int A[10] = {9,8,7,6,5,5,7,3,2,1};
	int B[10];
	countSort(A,B,10);
	return 0;
}

计数排序 C语言实现版

上一篇:Please ensure that adb is correctly located


下一篇:清理SQL数据库日志