Difference between qsort() and sort() ?

I tried solving the question HORSES < http://www.codechef.com/problems/HORSES > , according to my algorithm, I had to sort the array and compare the adjacent entries for minimum difference. My solution where I used qsort function of stdlib.h gave a WRONG ANSWER whereas when I used sort function of algortithm header file, it got accepted.

Whats the difference between the two sorting functions?
and is the use of algorithm.h only limited to C++ ?

using sort() which got accepted

using qsort of stdlib.h which gave a wrong answer

1 Like

First of all there is a slight error in your code. Your loop for finding the difference should run from index 0 to n-2 as you are finding the difference of indices i and (i+1) so that i+1 index should remain in the range.

But ignoring that case there is clearly some error as the same code using qsort() is giving wrong answer whereas using sort() is getting accepted.