Your two inner loops:
for(int i=mid;i<n;i++)
{
if (a[mid] ==val)
System.out.println("found"+val);
}
for(int i=0;i<mid;i++)
{
if ( a[mid] ==val)
System.out.println("found"+val);
}
Notice that you are accessing a[mid]
. mid
does not change throughout the loop; you meant to use a[i]
. Try replacing mid
with i
.
Also, you may want to look into indenting your code. What editor are you using to write your code?
strager
2010-07-18 05:46:05