I have an array which is sorted in descending order, with no duplicates. Can I perform binary search on it using bsearch function in libc ? To do this, do I need to alter the compare function that I am passing to it ?
Thanks
I have an array which is sorted in descending order, with no duplicates. Can I perform binary search on it using bsearch function in libc ? To do this, do I need to alter the compare function that I am passing to it ?
Thanks
Yes, you can use
bsearch. You will need to make sure yourcomparefunction agrees with the sort order of your array. In your case that might mean logically inverting the normal ascending/equal/descending order.