fork download
  1. #include <stdio.h>
  2. void swap(int* arr, int x, int y) {
  3. int temp = arr[x];
  4. arr[x] = arr[y];
  5. arr[y] = temp;
  6. }
  7. int partition(int* arr, int p, int r) {
  8. int x = arr[r];
  9. int i = p - 1;
  10. for (int j = 0; j < r; j++) {
  11. if (arr[j] <= x) {
  12. i++;
  13. swap(arr, i, j);
  14. }
  15. }
  16. i++;
  17. swap(arr, i, r);
  18. return i;
  19. }
  20.  
  21. void quick(int* arr, int p, int r) {
  22. if (p < r) {
  23. int q = partition(arr, p, r);
  24. quick(arr, p, q - 1);
  25. quick(arr, q + 1, r);
  26. }
  27. }
  28. int main(void) {
  29. // your code goes here
  30. int n = 0;
  31. scanf_s("%d", &n);
  32. int* arr = (int*)malloc(sizeof(int)*5000);
  33. int cnt = 1;
  34. for (int i = 0; i < n; i++) {
  35. scanf_s("%d", arr + i);
  36. if (i % 5000 == 0) {
  37. realloc(arr, sizeof(int) * 5000 * cnt);
  38. cnt++;
  39. }
  40. }
  41. quick(arr, 0, n - 1);
  42. for (int i = 0; i < n; i++) {
  43. printf("%d", arr[i]);
  44. }
  45. return 0;
  46. }
  47.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
5
1
3
4
2
5
compilation info
prog.c: In function ‘main’:
prog.c:31:2: warning: implicit declaration of function ‘scanf_s’; did you mean ‘scanf’? [-Wimplicit-function-declaration]
  scanf_s("%d", &n);
  ^~~~~~~
  scanf
prog.c:32:19: warning: implicit declaration of function ‘malloc’ [-Wimplicit-function-declaration]
  int* arr = (int*)malloc(sizeof(int)*5000);
                   ^~~~~~
prog.c:32:19: warning: incompatible implicit declaration of built-in function ‘malloc’
prog.c:32:19: note: include ‘<stdlib.h>’ or provide a declaration of ‘malloc’
prog.c:2:1:
+#include <stdlib.h>
 void swap(int* arr, int x, int y) {
prog.c:32:19:
  int* arr = (int*)malloc(sizeof(int)*5000);
                   ^~~~~~
prog.c:37:4: warning: implicit declaration of function ‘realloc’ [-Wimplicit-function-declaration]
    realloc(arr, sizeof(int) * 5000 * cnt);
    ^~~~~~~
prog.c:37:4: warning: incompatible implicit declaration of built-in function ‘realloc’
prog.c:37:4: note: include ‘<stdlib.h>’ or provide a declaration of ‘realloc’
/usr/bin/ld: /home/Jj2PIY/ccjVfg2f.o: in function `main':
prog.c:(.text.startup+0x2f): undefined reference to `scanf_s'
/usr/bin/ld: prog.c:(.text.startup+0x7b): undefined reference to `scanf_s'
collect2: error: ld returned 1 exit status
stdout
Standard output is empty