1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
|
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication1;
/**
*
*
*/
public class Sortieren_II {
public static <T> void sortieren_1 (T... feld) {
System.out.println("Das Feld ist: ");
for (int i = 0; i < feld.length; i++) {
System.out.print(" " + feld[i] + " ");
}
for (int i = 0; i < feld.length; i++) {
for (int j = i + 1; j < feld.length; j++) {
if (feld[i] > feld[j]) {
T tmp;
tmp = feld[i];
feld[i] = feld[j];
feld[j] = tmp;
}
}
}
System.out.println("Das geordnete Feld ist gleich: ");
for (int i = 0; i < feld.length; i++) {
System.out.print(" " + feld[i] + " ");
}
}
public static void main(String[] args) {
int[] feld = {2, 1, 5, 4, 7, 8, 3, 6};
sortieren_1(feld);
}
}
|