Files
python/TangDou/LuoGuBook/L9_2_BucketSort.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

29 lines
643 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 1e6 + 10;
int a[] = {1, 2, 5, 4, 3, 2};
int b[N];
int mx, mi = INF;
int main() {
// C++求整数数组长度的办法
int len = sizeof(a) / 4;
// sizeof(int);
//最大值,最小值
for (int i = 0; i < len; i++)
mx = max(mx, a[i]), mi = min(mi, a[i]); //最大值5最小值1
//放入桶
for (int i = 0; i < len; i++) b[a[i]]++;
//排序结果
for (int i = mi; i <= mx; i++) {
for (int j = 1; j <= b[i]; j++)
printf("%d ", i);
}
return 0;
}