Advertisement
Guest User

Untitled

a guest
Jan 27th, 2020
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "counting_sort.h"
  4.  
  5. void counting_sort(int *array, int length){
  6. //YOUR CODE STARTS HERE
  7. //YOUR CODE STARTS HERE
  8.  
  9.  
  10. // Deklarien von Maximum und Minimum
  11.  
  12. int min = array[0];
  13. int max = array[0];
  14. int i;
  15.  
  16.  
  17. // Bedingungen setzen
  18. for(i=0; i<length; i++){
  19. if (min>array[i])
  20. min = array[i];
  21. if(max<array[i])
  22. max = array[i];
  23. }
  24.  
  25. // Größe der Liste
  26. int k = max - min +1;
  27.  
  28. // Erstellen des Histrogramms
  29. int *histrogramm;
  30. histrogramm = (int*)calloc(k, sizeof(int));
  31.  
  32.  
  33. // Iteraieren der Liste
  34.  
  35. for (int i = 0; i < length; i++ ){
  36.  
  37. int p =array[i]- min;
  38. histrogramm [p]++;
  39.  
  40. }
  41.  
  42. // Durchlaufen der letzten Schleifen der Liste
  43. int h = 0;
  44. for (i=0; i < k ;i++){
  45.  
  46. while(histrogramm[i] < 0) {
  47. array[h] = i + min;
  48. histogram--;
  49. }
  50.  
  51. }
  52. free(histrogramm);
  53.  
  54. //YOUR CODE ENDS HERE
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement