Exforsys
+ Reply to Thread
Results 1 to 4 of 4

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 ...

  1. #1
    sammy is offline Senior Member Array
    Join Date
    Apr 2006
    Answers
    145

    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.


  2. #2
    ashlee is offline Senior Member Array
    Join Date
    Apr 2006
    Answers
    108
    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.


  3. #3
    hvg_99 is offline Junior Member Array
    Join Date
    May 2007
    Answers
    9

    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


  4. #4
    sammy is offline Senior Member Array
    Join Date
    Apr 2006
    Answers
    145
    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



Latest Article

Network Security Risk Assessment and Measurement

Read More...