mirror of
https://github.com/DerTyp7/lf05-java.git
synced 2025-11-02 14:22:30 +01:00
Sortieralgoritmus
This commit is contained in:
30
src/strategyPattern/Bubblesort.java
Normal file
30
src/strategyPattern/Bubblesort.java
Normal file
@@ -0,0 +1,30 @@
|
||||
package strategyPattern;
|
||||
|
||||
public class Bubblesort implements ISortieralgorithmus {
|
||||
@Override
|
||||
public double[] sortiereAbsteigend(double[] array) {
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
for (int j = 0; j < array.length - 1; j++) {
|
||||
if (array[j] < array[j + 1]) {
|
||||
double temp = array[j];
|
||||
array[j] = array[j + 1];
|
||||
array[j + 1] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
return array;
|
||||
}
|
||||
@Override
|
||||
public double[] sortiereAufsteigend(double[] array) {
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
for (int j = 0; j < array.length - 1; j++) {
|
||||
if (array[j] > array[j + 1]) {
|
||||
double temp = array[j];
|
||||
array[j] = array[j + 1];
|
||||
array[j + 1] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
return array;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user