public static int binRecSearch (int[] field, int key){
int Anfang = 0;
int Ende = field.length -1;
return binRecSearch(field, key, Anfang, Ende);
}
public static int binRecSearch (int[] field, int key, int Anfang, int Ende){
while (Anfang<=Ende){
int Mitte = (Anfang+Ende)/2;
if (Mitte==key)
return Mitte;
else if (field[Mitte] > key)
binRecSearch(field, key, Anfang, Mitte-1);
else
binRecSearch(field, key, Mitte+1, Ende);
}
return -1;
}
public static void main(String[] args){
int [] array2 = new int[4];
array2[0]=2;
array2[1]=5;
array2[2]=6;
array2[3]=8;
System.out.println(binRecSearch(array2, 5));
}
Das Programm wird ohne Fehlermeldung ausgeführt, braucht aber extrem lange und zudem wird einfach nach erfolgreicher Ausführung nichst auf der Konsole ausgegeben
(ich versuche eine rekursive binär Suche zu programmieren)
int Anfang = 0;
int Ende = field.length -1;
return binRecSearch(field, key, Anfang, Ende);
}
public static int binRecSearch (int[] field, int key, int Anfang, int Ende){
while (Anfang<=Ende){
int Mitte = (Anfang+Ende)/2;
if (Mitte==key)
return Mitte;
else if (field[Mitte] > key)
binRecSearch(field, key, Anfang, Mitte-1);
else
binRecSearch(field, key, Mitte+1, Ende);
}
return -1;
}
public static void main(String[] args){
int [] array2 = new int[4];
array2[0]=2;
array2[1]=5;
array2[2]=6;
array2[3]=8;
System.out.println(binRecSearch(array2, 5));
}
Das Programm wird ohne Fehlermeldung ausgeführt, braucht aber extrem lange und zudem wird einfach nach erfolgreicher Ausführung nichst auf der Konsole ausgegeben
(ich versuche eine rekursive binär Suche zu programmieren)