Source code - binary.cpp

Find C and C++ source code to help you learn to program. You can submit your own code, or you can simply browse and download the code of others.

Finally, you might want to check out Code Cogs - An Open Source Scientific Library / Database in C++ for more code.

Index :: Algorithms :: Searching / binary.cpp
binary.cpp
resource information
Title binary.cpp
URL http://www.cprogramming.com/source/binary.cpp
Category 10
Description binary search that returns a negative one if the number is not found This code does a bubble sort and then proforms the binary search
Contact David Thompson
Added 08-10-2002 at 01:30 p.m.
Last Updated 08-10-2002 at 01:32 p.m.
rating
Current Rating 4.5
Rate Resource
 
reviews
Number of Reviews 2
Review this Resource
Reviews:
  • 1
    posted at 11:25 a.m. on 06-15-2013
  • It is an ok source, it could have been written better. The code needs to be changed in the do loop so there are not any more errors or crashes. (ex: do { if(b > a[mid]) { low = mid + 1; mid = (high + low) / 2; } else if(b < a[mid]) { high = mid - 1; mid = (high + low) / 2; } else if(b == a[mid]) { return mid + 1; } }while(low < high); But otherwise is good.
    posted at 06:25 p.m. on 02-13-2006