Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include "d2s.h"
  2. #include "common.h"
  3. void merge_sort_merge_seq(int* array, unsigned l, unsigned m, unsigned h)
  4. {
  5. unsigned i = l, j = m + 1, k = 0;
  6. int tmp[h - l + 1];
  7. while (i <= m && j <= h) {
  8. if (array[i] <= array[j]) {
  9. tmp[k++] = array[i++];
  10. }
  11. else {
  12. tmp[k++] = array[j++];
  13. }
  14. }
  15. while (i <= m) {
  16. tmp[k++] = array[i++];
  17. }
  18. while (j <= h) {
  19. tmp[k++] = array[j++];
  20. }
  21. for (--k; k != (unsigned)-1; --k) {
  22. array[l + k] = tmp[k];
  23. }
  24. }
  25. void merge_sort_sub_seq(int* array, unsigned l, unsigned h)
  26. {
  27. if (l < h) {
  28. unsigned m = (l + h) / 2;
  29. merge_sort_sub_seq(array, l, m);
  30. merge_sort_sub_seq(array, m + 1, h);
  31. merge_sort_merge_seq(array, l, m, h);
  32. }
  33. }
  34. void merge_sort_seq(int* array, unsigned s)
  35. {
  36. merge_sort_sub_seq(array, 0, s - 1);
  37. }