bool compareTwoShipments( const Shipment& a, const Shipment& b )
{
// return true only if a compares less than b by (year, month, and day)
return (a.year < b.year) or ((a.year == b.year)
and ((a.month < b.month) or ((a.month == b.month)
and (a.day < b.day))));
}
void sortShipments( Shipment shipments[], int totalShipments )
{
int i, j; // loop counters
int iMin; // index of element to swap with element j
for (j = 0; j < totalShipments - 1; j++)
{
// Find the next shipment in the remaining unsorted shipments
iMin = j;
for (i = j + 1; i < totalShipments; i++)
{
if (compareTwoShipments( shipments[i], shipments[iMin] ))
{
iMin = i;
}
}
swap( shipments[j], shipments[iMin];
}
}
It is late and my brain may have failed here. But that should be right...