#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.uj5u.com/houduan/69211.html
標籤:C
上一篇:c語言請教大佬
