Hallo Leute, irgendwie stehe ich auf dem Schlauch. Ich will ein Array (bestehend aus uint16 Einträgen) an meine Bubblesort funktion weiterreichen. Der Code der Bubblesort-Funktion funktioniert, allerdings nur wenn er nicht in einer Funktion ausgelagert ist. Deswegen denke ich, dass das Problem bei der Übergabe des Arrays liegt. Mein Code:
1 | void bubbleSort(uint16_t *table[], uint8_t tableLen){
|
2 | for(uint8_t f = 0; f < (tableLen - 1); f++){
|
3 | for(uint8_t s = 0; s < (tableLen - f - 1); s++){
|
4 | if(*table[s] > *table[s+1]){ // Tauschen
|
5 | uint16_t temp = *table[s+1]; |
6 | *table[s+1] = *table[s]; |
7 | *table[s] = temp; |
8 | } |
9 | } |
10 | } |
11 | } |
12 | |
13 | int main(void){
|
14 | |
15 | uint16_t test[20] = {21436, 3625, 1876, 27, 8799, 51112, 98, 625, 1, 6365, 1982, 12663, 7663, 41228, 8726, 1253, 9817, 1234, 17263, 7671};
|
16 | bubbleSort(&test, 20); |
17 | |
18 | [...] |
19 | |
20 | } |
Wenn ich den Code debugge, läuft der uC erst einmal in die erste Schleife, macht die zweite zu ende und springt dann ins Nirvana - warum auch immer. Vielleicht weiß jemand, was hier falsch läuft. Gruß