Download benchmarks/Algorithms/bucket_sort/solution.c from PV-SJTU/PV-Bench: direct link, hf CLI and curl.
- Browser
- Download file 907 Bytes
-
https://huggingface.co/datasets/PV-SJTU/PV-Bench/resolve/main/benchmarks/Algorithms/bucket_sort/solution.c
- Command line
-
hf download hf://datasets/PV-SJTU/PV-Bench/benchmarks/Algorithms/bucket_sort/solution.c
-
curl -L -o solution.c https://huggingface.co/datasets/PV-SJTU/PV-Bench/resolve/main/benchmarks/Algorithms/bucket_sort/solution.c
907 Bytes
| void sort(int *a, int n) | |
| { | |
| if (n <= 1) { | |
| return; | |
| } | |
| int max_value = a[0]; | |
| for (int i = 1; i < n; ++i) { | |
| if (a[i] > max_value) { | |
| max_value = a[i]; | |
| } | |
| } | |
| int output[1000]; | |
| int count[10]; | |
| for (int exponent = 1; max_value / exponent > 0; exponent *= 10) { | |
| for (int digit = 0; digit < 10; ++digit) { | |
| count[digit] = 0; | |
| } | |
| for (int i = 0; i < n; ++i) { | |
| int digit = (a[i] / exponent) % 10; | |
| ++count[digit]; | |
| } | |
| for (int digit = 1; digit < 10; ++digit) { | |
| count[digit] += count[digit - 1]; | |
| } | |
| for (int i = n - 1; i >= 0; --i) { | |
| int digit = (a[i] / exponent) % 10; | |
| --count[digit]; | |
| output[count[digit]] = a[i]; | |
| } | |
| for (int i = 0; i < n; ++i) { | |
| a[i] = output[i]; | |
| } | |
| } | |
| } | |