Also, qsort has a friend called bsearch.
If you look at the example here: https://man7.org/linux/man-pages/man3/bsearch.3.html First the array is sorted by name. Then bsearch is used for lookup. If the array had millions, using bsearch is a lot faster, because it doesn't have to search through the entire array. And the comparison function is the same. |
Off: for learners, it would be an interesting exercise to find the missing features in bsearch(3)
For example the lack of user-parameter in callback (compare qsort(3) and qsort_r(3)) |
All times are GMT -5. The time now is 10:03 AM. |