Advertisement
Guest User

Untitled

a guest
Nov 18th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. /* === INTROPROG ABGABE ===
  2. * Blatt 1, Aufgabe 2
  3. * Tutorium: t33
  4. * Abgabe von: Robin Rönick
  5. * ========================
  6. */
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include "arrayio.h"
  11.  
  12. int MAX_LAENGE = 1000;
  13. int MAX_VALUE = 100;
  14.  
  15. void count_sort_calculate_counts(int input_array[], int len, int count_array[]) {
  16. for(int i = 0; i <= MAX_VALUE; i++){
  17. count_array[i] = 0;
  18. }
  19. for(int j = 0; j < len; j++){
  20. count_array[input_array[j]] = count_array[input_array[j]] + 1 ;
  21. }
  22.  
  23. }
  24.  
  25. void count_sort_write_output_array(int output_array[], int len, int count_array[]) {
  26. int k = 0;
  27. for(int j = 0; j <= len; j++){
  28. for(int i = 0; i < count_array[j]; i++){
  29. output_array[k] = j;
  30. k = k + 1;
  31. }
  32. }
  33. }
  34.  
  35.  
  36.  
  37. int main(int argc, char *argv[]) {
  38.  
  39. if (argc < 2){
  40. printf("Aufruf: %s <Dateiname>\n", argv[0]);
  41. printf("Beispiel: %s zahlen.txt\n", argv[0]);
  42. exit(1);
  43. }
  44.  
  45. char *filename = argv[1];
  46.  
  47. int input_array[MAX_LAENGE];
  48. int len = read_array_from_file(input_array, MAX_LAENGE, filename);
  49.  
  50. printf("Unsortiertes Array:");
  51. print_array(input_array, len);
  52.  
  53. // HIER alle nötigen Deklarationen und Funktionsaufrufe für Count Sort einfügen
  54. int output_array[MAX_LAENGE];
  55. int count_array[MAX_LAENGE];
  56. count_sort_calculate_counts(input_array, len, count_array);
  57. count_sort_write_output_array(output_array, MAX_VALUE, count_array);
  58.  
  59.  
  60.  
  61.  
  62.  
  63. printf("Sortiertes Array:");
  64. // Folgende Zeile einkommentieren, um das Array auszugeben
  65. print_array(output_array, len);
  66.  
  67. return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement