How does the compare function in qsort work?

前端 未结 6 1217
隐瞒了意图╮
隐瞒了意图╮ 2020-12-06 03:36

I found this sample code online, which explains how the qsort function works. I could not understand what the compare function returns.

#include         


        
6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-06 03:57

    a and b are being compared as integers - they have to be passed in as void * but are then cast to int * before finally being deferenced. As for the return value, it will either be positive, negative, or zero, all of which would be taken into account in the sorting function.

提交回复
热议问题