Is there a way to sort a struct of vectors? Given my struct looks like this
struct Data
{
std::vector<std::string> Dates;
std::vector<double> DateSeconds, other1, other2, other3, other4, other5;
};
And the way I sort by (lets take DateSeconds
) is,
int __cdecl CompareWithDateSeconds(const void* lhs, const void* rhs)
{
for (int i = 0; i < m_DataSize; i++) {
const Data* a = (const Data*)lhs;
const Data* b = (const Data*)rhs;
double delta = a->DateSeconds[i] - b->DateSeconds[i];
if (delta > 0)
return (SortDirection == Ascending) ? +1 : -1;
if (delta < 0)
return (SortDirection == Ascending) ? -1 : +1;
}
}
and then
qsort(&m_Data.DateSeconds[0], m_DataSize, sizeof(m_Data.DateSeconds[0]), CompareWithDateSeconds);