import java.io.*; import java.util.*; class BinSearch { private int size; private int[] a; private int index; public int n=0; //----------------------------------------------------------------------------------------- // constructor defined //----------------------------------------------------------------------------------------- public BinSearch(int Max) { size=Max; a=new int[size]; index=0; } //----------------------------------------------------------------------------------------- // inserting an element in the array //----------------------------------------------------------------------------------------- public void insert(int val) { try { a[index++]=val; n=index; } catch(Exception e) { System.out.println("e.getMessage"); } } //----------------------------------------------------------------------------------------- // Searching the element by Binary search // method //---------------------------------------------------------------------------------------- public void Search(int low,int high,int key) { int mid; if(low>high) { System.out.println(" Error! It is not present in the list"); return; } mid=(low+high)/2; if(key==a[mid]) System.out.println("\nThe element is present at location "+(mid+1)); else if(keya[mid]) Search(mid+1,high,key); } //---------------------------------------------------------------------------------------- // Displaying the elements of an array //---------------------------------------------------------------------------------------- public void display() { System.out.println("\n The elements are"); for(int i=0; i