Replace qsort with std::sort

This commit is contained in:
2024-04-24 21:02:34 -04:00
parent 20c0a8e258
commit 17c8c9aed4
+9 -14
View File
@@ -21,6 +21,8 @@
#include <vector>
#include <memory>
#include <algorithm>
#include <iostream>
#include "../gamestr.h"
#include "../starmap.h"
@@ -29,40 +31,33 @@
#include "../sis.h"
#include "../sounds.h"
static int
compStarName (const void *ptr1, const void *ptr2)
static bool
compStarName (const int index1, const int index2)
{
int index1;
int index2;
index1 = *(const int *) ptr1;
index2 = *(const int *) ptr2;
if (star_array[index1].Postfix != star_array[index2].Postfix)
{
return utf8StringCompare (GAME_STRING (star_array[index1].Postfix),
GAME_STRING (star_array[index2].Postfix));
GAME_STRING (star_array[index2].Postfix)) < 0;
}
if (star_array[index1].Prefix < star_array[index2].Prefix)
return -1;
return true;
if (star_array[index1].Prefix > star_array[index2].Prefix)
return 1;
return 0;
return false;
}
static void
SortStarsOnName (STAR_SEARCH_STATE *pSS)
{
std::cerr << "ADAM C++: Star sorting!" << std::endl;
int i;
int *sorted = pSS->SortedStars;
for (i = 0; i < GetStarCount(); i++)
sorted[i] = i;
std::qsort (sorted, GetStarCount(), sizeof (int), compStarName);
std::sort( sorted, sorted + GetStarCount(), compStarName );
}