
- Forum
- Programming Talk
- C and C++
- Highlight the Purpose
Highlight the Purpose
This is a discussion on Highlight the Purpose within the C and C++ forums, part of the Programming Talk category; I saw two functions qsort() and bsearch() recently in one C book. But I could not get the usage of ...
-
Highlight the Purpose
I saw two functions qsort() and bsearch() recently in one C book. But I could not get the usage of this. What is the purpose of these functions.
-
qsort function is used for sorting elements in an array given. It takes parameter as pointer to first element of the array given for sorting, the size of each of the array element in bytes, number of elements in array, pointer to elements of array.
-
Hightlight the purpose..qsort() & bsearch()
Hi,
qsort() function is used to sort a big array or a linked list. It is a kind of sorting where a key is found out by using some formula and is placed at the center of the array. Then you sort the array using some logic. If you want i can explain with an example.
bsearch() function is used to search for an element in the array. There are basically two types of searches.
1. Linear search
2. Binary Search ( bsearch())
For linear search you keep search for an element irrespective of the array is sorted or not. but in case of binary search the pre requisite is that the array must be in sorted in order, if not then first thing is to sort the array and then perform the search. I can also explain this also.
As your query was just to know the purpose of these two functions so i did not explain with an example. If you really feel i can explain them with an example.
I hope i have cleared your doubt.
Regards,
Bangalore
-
I could get a clear overview about qsort() function and bsearch() function. If you could explain them with an example it would help me further to understand these concepts in detail.
-
Sponsored Ads

Reply With Quote





