Hey, I'm using a database and im trying to sort a 2D array info[51][10] that contains 51 pieces of records and 10 different fields for each record.
And, now I'm trying to sort a desired field in the 2D array alphabetically.
However, the other fields within the same record should be swapped together. (So that the information of the same records stays together).
Also, I am constantly experiencing a run-time error.
Sometimes my program works sometimes the whole thing crashes...
By opening the code in different folders sometimes works. But the problem is still here. Is there any way to fix this error?
#include <algorithm>
struct RecordInfo
{
std::string recordName;
std::string artistName;
/*...*/
};
//This is custom functor to use in std::sort, you can still sort manually
struct SortByName
{
booloperator()(const RecordInfo& lhs, const RecordInfo& rhs)
{
return lhs.recordName < rhs.recordName;
}
};
int main()
{
RecordInfo info[51];
//initialize your array here
std::sort(info, info+51, SortByName()); //Sorting
//Or use your sorting algorithm here.
//You will have to only swap structs encapsulating all data in one piece
//so you do not need to make sure that everything is swapped properly
}