How can I sort the CCArray?

How can I sort the CCArray?
0.0 0


I found some information.

but I don’t know why it removed and it work correctly.

plz help me :frowning:


why not use qsort?


How qsort help the CCArray sorting,
can you share the example to work.



Please refer to CCTouchDispatcher::rearrangeHandlers.

void CCTouchDispatcher::rearrangeHandlers(CCArray *pArray)
    // FIXME: qsort is not supported in bada1.0, so we must implement it ourselves.
    qsort(pArray->data->arr, pArray->data->num, sizeof(pArray->data->arr[0]), less);


Thanks you very much


Minggo Zhang wrote:

Please refer to CCTouchDispatcher::rearrangeHandlers.

I tried to use qsort to sort a CCArray of objects of a class that extends CCObject but it doesn’t work.
Looking at the following thread in stackoverflow it seems that it’s better use std:sort (
Now the following solution with std::sort works correctly:

static bool compareScores(const void* p1, const void* p2)
  ZScore* score1 = (ZScore*)p1;
  ZScore* score2 = (ZScore*)p2;
  bool result = score1->raceTime() < score2->raceTime();
  return result;

bool ZBestScorePersistence::saveBestScore(ZScore* _score)
            m_bestScores->data->arr + m_bestScores->data->num,
  return true;


qsort works fine, example:

int compare(const void* a, const void* b)
YourType* friendA = (YourType**)a;
YourType** friendB = (YourType*)b;

return friendA~~>getScore>friendB~~>getScore();

void YourClass::yourMethod()
qsort(yourCCArray~~>data~~>arr, yourCCArray~~>data~~>num, sizeof(long), compare);