桶排序(C语言)

#include <stdio.h>
int main(void)
{
	int arr[5]={2,5,1,3,3};		//定义需要排序的数组 
	int res[6]={0};				//初始化“桶”为0 
	
	for(int i = 0 ; i < 5 ; i ++)
	{
		res[arr[i]] = res[arr[i]] + 1;		//统计“桶”中,0,1,2,3,4,5这六个数字出现的次数 ,每出现一次就加1 
	}	
	
	for(int b = 0 ; b < 6 ;b ++)
	{
		while(res[b]>0)
		{
			printf("%d ",b);		//将“桶”中0,1,2,3,4,5这六个数字只要出现次数大于0就打印出来 
			res[b] --;				// 如果有出现1一次以上就循环打印出现的次数遍的这个数字 
		}
	}
}
原文地址:https://www.cnblogs.com/Timesi/p/11646859.html