+ 2

How to use the qsort function ?

I need a lot of explanation about this function ! Please help me🙏

31st Mar 2019, 10:01 AM
Mamadou Moustapha Diallo
Mamadou Moustapha Diallo - avatar
2 Respuestas
+ 6
qsort takes 4 arguments, but the first three are kind of obvious: The array, its length, the size of its type. The tricky part is the function that determines how/what is sorted. It needs to take two void pointers and return an int. The two args are the two values in your array that are going to be sorted at each step. Internally, you have to build this function so that it compares the two values and returns an int < 0 if the left operand is smaller, > 0 if it's bigger, and 0 if it's ==. Preferably you just return - 1, 0 or 1. Example: https://code.sololearn.com/cNPHNt8zNfti/?ref=app
31st Mar 2019, 10:12 AM
HonFu
HonFu - avatar
+ 2
Great ! A bit unmytified ! thanks a lot bro. I would have fro two to five exercises & assimilate that. Thanks a lot once more
31st Mar 2019, 10:16 AM
Mamadou Moustapha Diallo
Mamadou Moustapha Diallo - avatar