hi alle;
ich habe ein Stück Java Codes gefunden in iNet gefunden:
public class insSort{
public static void main(String[] args) {
int[] unsortiert = { 4, 1, 8, -3, 5, 7 };
int[] sortiert = insertionSort(unsortiert);
for (int i = 0; i < sortiert.length; i++) {
System.out.print(sortiert + ", ");
}
}
public static int[] insertionSort(int[] sortieren) {
int temp;
for (int i = 1; i < sortieren.length; i++) {
temp = sortieren;
int j = i;
while (j > 0 && sortieren[j - 1] > temp) {
j--;
}
sortieren[j] = temp;
}
return sortieren;
}
}
???:L
Eine Dummy Frage :
ist die Zeile int temp; unter insertionSort(int sortieren) nicht notwendigerweise als sortieren[0] in for- loop zu initialisieren ? Der temp muss doch hier Anfangswert haben, bevor man es mit seinen Nachbarn vertauschen kann.
Erklärung bitte .Sorry nochmal , um euch Mühe dazu zu machen.
lg
wil89
ich habe ein Stück Java Codes gefunden in iNet gefunden:
public class insSort{
public static void main(String[] args) {
int[] unsortiert = { 4, 1, 8, -3, 5, 7 };
int[] sortiert = insertionSort(unsortiert);
for (int i = 0; i < sortiert.length; i++) {
System.out.print(sortiert + ", ");
}
}
public static int[] insertionSort(int[] sortieren) {
int temp;
for (int i = 1; i < sortieren.length; i++) {
temp = sortieren;
int j = i;
while (j > 0 && sortieren[j - 1] > temp) {
j--;
}
sortieren[j] = temp;
}
return sortieren;
}
}
???:L
Eine Dummy Frage :
ist die Zeile int temp; unter insertionSort(int sortieren) nicht notwendigerweise als sortieren[0] in for- loop zu initialisieren ? Der temp muss doch hier Anfangswert haben, bevor man es mit seinen Nachbarn vertauschen kann.
Erklärung bitte .Sorry nochmal , um euch Mühe dazu zu machen.
lg
wil89
Zuletzt bearbeitet: