I noticed that qsort code listed above doesn't work if you pass in a dynamic structure array initialized by new or calloc.

how should the call to qsort & the compare function be rewritten then?