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