danke!
Es funktioniert allerdings bei Arduino offenbar auch ohne <int>, aber ich werde es mir merken, ggf für den Raspi!
Code:
//---------------------------------------------------------
// Bubble Sort
//---------------------------------------------------------
template <typename VTYPE> void bubblesort(VTYPE *array, int length) {
VTYPE tmp;
for (int i=0; i<length-1; i++) {
for (int j=0; j<length-i-1; j++) {
if (array[j] > array[j+1]) {
tmp = array[j];
array[j] = array[j+1];
array[j+1] = tmp;
}
}
}
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("\nSerial started...\n");
int intarray[3]={3,5,1};
bubblesort(intarray, 3);
for(int i=0; i<3; i++) Serial.println(intarray[i]);
float floatarray[3]={5.0,1.0,3.0};
bubblesort(floatarray, 3);
for(int i=0; i<3; i++) Serial.println(floatarray[i]);
}
void loop() {
// put your main code here, to run repeatedly:
}
Ausgabe:
Code:
Serial started...
1
3
5
1.00
3.00
5.00
Lesezeichen