Compare commits

...
2 Commits
Author SHA1 Message Date
paulusja 67ae1ba1ca Add previous solution for selection sort. 2026-06-18 09:24:12 +02:00
paulusja cbe48ba34f Use unsigned. 2026-06-18 09:23:11 +02:00
2 changed files with 29 additions and 3 deletions

No files matched your search

+25
View File
@@ -6,3 +6,28 @@ void tausche(int *zahl1, int *zahl2)
*zahl1 = *zahl2;
*zahl2 = tmp;
}
unsigned int findeMaxIdx(int array[], unsigned int len)
{
unsigned int maxIdx = 0;
for(int i = 1; i < len; i++)
{
if(array[i] > array[maxIdx])
{
maxIdx = i;
}
}
return maxIdx;
}
void selectionsort(int array[], unsigned int len)
{
for(int unsortierteLaenge = len; unsortierteLaenge >= 2; unsortierteLaenge--)
{
unsigned int maxIdx = findeMaxIdx(array, unsortierteLaenge);
tausche(&array[maxIdx], &array[unsortierteLaenge-1]);
}
}
+4 -3
View File
@@ -2,8 +2,9 @@
#define SORTIERUNG_H
void tausche(int *zahl1, int *zahl2);
void selectionsort(int array[], int anzahl);
void insertionsort(int array[], int anzahl);
void bubblesort(int array[], int anzahl);
void selectionsort(int array[], unsigned int anzahl);
void insertionsort(int array[], unsigned int anzahl);
void bubblesort(int array[], unsigned int anzahl);
unsigned int findeMaxIdx(int array[], unsigned int len);
#endif