Guest User

Untitled

a guest
May 22nd, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.17 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main(int argc, char *argv[])
  5. {
  6.     void Testfall(int id, short array, int length);
  7.     void sortiereAbsteigend(short* array, int length);
  8.     short* array[12] = {5, 16 ,7, 12, 1, 33, 100, 67, 45, 11, 21, 27};
  9.     printf("Testrahmen \n");
  10.  
  11.     Testfall(1, array, 2);
  12.     Testfall(2, array, 6);
  13.     Testfall(3, array, 12);
  14.  
  15.     return 0;
  16. }
  17.  
  18.  
  19. void Testfall(int id, short* array, int length)
  20. {
  21.      //printf("Testfall%d Ein: %s Aus: %s\n", id, array, sortiereAbsteigend(array, length);
  22. }
  23.  
  24. void sortiereAbsteigend(short* array, int length)
  25. {
  26.     short max;
  27.     int index;
  28.     short temp;
  29.     int i, j;
  30.     max = 0;
  31.     for(i = 0; i < length; i++) {
  32.           array[i] = temp; // ersten Wert der Teilfolge sichern
  33.     // Maximalwert suchen:
  34.     max = -32768;
  35.     for(j = i; j < length; j++) {
  36.           if(array[j] >= max) {
  37.                       max = array[j];
  38.                       index = j;
  39.                       }
  40.                       }
  41.         // gefundenen Maximalwert an erste Stelle setzen
  42.         array[i] = array[index];
  43.         // und mit erstem Datensatz tauschen:
  44.         array[index] = temp;
  45.     }
  46. }
Add Comment
Please, Sign In to add comment