You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
942B

  1. //
  2. // Created by red on 01/12/19.
  3. //
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <time.h>
  7. #include "sorts.h"
  8. void print_elements(double* arr, size_t n) {
  9. printf("Elements of array:\n");
  10. for (size_t i = 0; i < n; i++) {
  11. printf("%.4f ", arr[i]);
  12. }
  13. printf("\n");
  14. }
  15. void init_arr(double* arr, size_t n) {
  16. for (size_t i = 0; i < n; i++ ){
  17. arr[i] = (double) (rand() % (2 << 10)) / 42;
  18. }
  19. }
  20. int main() {
  21. srand(time(0));
  22. puts("Testing quicksort...");
  23. double* arr = calloc(10, sizeof(double));
  24. init_arr(arr, 10);
  25. print_elements(arr, 10);
  26. quicksort(arr, 10);
  27. print_elements(arr, 10);
  28. puts("Sorted!");
  29. puts("Testing shellsort...");
  30. init_arr(arr, 10);
  31. print_elements(arr, 10);
  32. shellsort(arr, 10);
  33. print_elements(arr, 10);
  34. puts("Sorted!");
  35. puts("Testing selection sort...");
  36. init_arr(arr, 10);
  37. print_elements(arr, 10);
  38. selectionsort(arr, 10);
  39. print_elements(arr, 10);
  40. puts("Sorted!");
  41. }