
binary search
once again probably trivial, and i can't seem to find this stuff anywhere.
i've created a binary search
Code:
int Narray::find(int low, int high, int num)
{
while (low == high)
{
int mid = (low + high) 2;
if (num >= marray.a[mid])
{
low = mid + 1;
}
else if (num <= marray.a[mid])
{
high = mid  1;
}
else
{
cout << The number was found in slot << marray.a[mid];
}
}
return 1;
}
it is part of a class function.my question is how do i get the values low and high, to pas to the function from main(). i know that the high and low should be the contents of the min slot number and the max slot number but i just can't seem to pass them right... :rolleyes:
thanks for any help

firstly
while (low = high)
should be low==high

secondly
i fail to see the usage of the return 0 right after the return 1

um... if low was eqaul to high, then your number was not found eh? and why are you saying Code:
if (num marray.a[mid])
?
there is no comparison made. unless you want to know if num is just as spaced out as marray.a[mid] but this is still the wrong syntax...

thirdly
else if (num marray.a[mid])
this wont even compile

sorry about that when i coupied the code it musta deleted some of my equal signs cuz they were all there i swear...i'll fix it in the first post...

jlf029 you're a copycat... what part of wrong syntax don't you understand? of course wrong syntax won't compile. anyway it doesn't matter. just letting you know that i know that you copied me... :)