Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static boolean sucheBinaer( int wert, int[] array){
- if(array.length==1) {
- if(wert==array[0]){ return true;
- }else{
- return false;
- }
- }
- int center = (array.length/2);
- if(array[center]==wert){
- return true;
- }
- else if(wert<array[center]){
- int[] arr = new int[center];
- for(int k=0; k<center;k++){
- arr[k]=array[k];
- }
- return sucheBinaer(wert,arr);
- }else{
- int[] arr = new int[array.length-center];
- for( int j=0; j<arr.length;j++){
- arr[j]=array[j+center];
- }
- return sucheBinaer(wert,arr);
- }
- }
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- int[] arr = {6,7,8,9,10,11};
- System.out.println(sucheBinaer(11,arr));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement