Showing posts with label easiest searching method. Show all posts
Showing posts with label easiest searching method. Show all posts

Friday, 3 February 2012

What is the easiest searching method to use?

Just as qsort() was the easiest sorting method, because it is part of the standard library, bsearch() is the easiest searching method to use.

Following is the prototype for bsearch():

void *bsearch(const void *key, const void *buf, size_t num, size_t size, int (*comp)(const void *, const void *));


The bsearch() function performs a binary search on an array of sorted data elements. A binary search is another “divide and conquer” algorithm. The key is compared with the middle element of