Hi, I want to sort an array of struct 'Workshops' in accordance with its member variable 'start_time'. I thought of using std::sort for the array and supplying 'CompareWorkshops' function as the third parameter-
bool CompareWorkshops(Workshops W1, Workshops W2)
{
return (W1.start_time <= W2.start_time);
}
//calculate max no. of non-overlapping workshopes that can be attended at once
int CalculateMaxWorkshops(Available_Workshops* ptr)
{
//to proceed, need to sort Workshops in accordance with their start_time
sort(ptr->array.begin(), ptr->array.end(), CompareWorkshops);
int i{ 0 }, count{ 0 }, previous_end{ 0 };
do
{
if (ptr->array[i].start_time >= previous_end) {
count += 1;
previous_end += ptr->array[i].end_time;
}
i++;
} while (i < ptr->n);
return count;
}
But I get this error after supplying inputs through console-
Is the error caused by sort() or something else?