fork download
  1. namespace RadixSort { //by Sergey Kopeliovich
  2.  
  3. enum {maxn = 5010, BN = 16, maxC = 1 << BN};
  4.  
  5. int n, a[maxn], b[maxn], cnt[maxC + 1];
  6.  
  7. void Sort() {
  8.  
  9. n = 5000;
  10.  
  11. for (int i = 0; i < n; ++i) {
  12. a[i] = rand() + 5 * rand();
  13. }
  14.  
  15. for (int t = 0; t < 2; ++t) {
  16. #define GET(i) ((a[i] >> (t * BN)) & (maxC - 1))
  17. memset(cnt, 0, sizeof(cnt));
  18. for (int i = 0; i < n; ++i) {
  19. ++cnt[GET(i) + 1];
  20. }
  21. for (int i = 0; i < maxC - 1; ++i) {
  22. cnt[i + 1] += cnt[i];
  23. }
  24. for (int i = 0; i < n; ++i) {
  25. b[cnt[GET(i)]++] = a[i];
  26. }
  27. for (int i = 0; i < n; ++i) {
  28. a[i] = b[i];
  29. }
  30. }
  31. }
  32.  
  33. };
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘void RadixSort::Sort()’:
prog.cpp:12:20: error: ‘rand’ was not declared in this scope
             a[i] = rand() + 5 * rand();
                    ^~~~
prog.cpp:17:13: error: ‘memset’ was not declared in this scope
             memset(cnt, 0, sizeof(cnt));
             ^~~~~~
prog.cpp:17:13: note: ‘memset’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
prog.cpp:1:1:
+#include <cstring>
 namespace RadixSort { //by Sergey Kopeliovich
prog.cpp:17:13:
             memset(cnt, 0, sizeof(cnt));
             ^~~~~~
stdout
Standard output is empty