Hi, I'm sure this will be an easy one for lots of folks out there, but I'm stumped. My code compiles but I get an "Arrayoutofbounds exception and I can't spot where my mistake lies. Any suggestions? It's a binary search code. I suspect the problem lies in the sort.
public class Binary{ //** declarations of variables int[] list,list_search; int size,count; long time1; long time2;
//** constructor public Binary(int n, int k){ size=n; count=k; int i; list=new int[size]; list_search=new int[count]; time1 = 0; time2 = 0;
//** generate the list of elements for(i=0;i<size;i++){ list=1+(int)(n*Math.random()); } for(i=0;i<count;i++) list_search=1+(int)(n*Math.random()); //sort the list sort(); //search the element startsearch(); }
//** sort the list before binary search... done in ascending order public void sort(){ int i, j, increment, temp;
//** main function public static void main(String args[]){ int n,k; if(args.length!=2){ System.out.println("Required number of arguments are not provided"); } else{ n=Integer.parseInt(args[0]);//parsing the size for number of elements in the list k=Integer.parseInt(args[1]);// parsing the size of number of elements to be searched Binary ss =new Binary(n,k);//object created to compare the two search