# sorting

• 03-11-2002
sorting
hi

i can't figure out a way to sort my staffs' id according to date.

Can anyone help me out??

Because i wanna show the latest leaves taken by which person
thanks!
• 03-11-2002
Syneris
a long int allows easy sorting in chronological order using this format: yyyymmdd

this is (year * 10000) + (month * 100) + day
• 03-11-2002
huh?

i don't get it....that seems like a mathematical calculation only

i need to sort with the following sequence:

1.) Month
2.) Date

Then the latest staff who took leave would be displayed in ascending/descending order
• 03-11-2002
Unregistered
convert the date fields to a single variable using the technique as described. or similar, if you prefer. Sort that field. It will be a lot easier than doing a double sort where you sort by month first and then by day.

struct Date
{
int month;
int day;
};

struct Employee
{
Date lastVacationDay;
long sortDate;
void convertDate(Date);
};

void Employee::convertDate(Date lastVacationDay)
{
sortDate = (lastVacationDay.month *100) + lastVacationDay.day;
}

int main()
{
//array of employees
Employee employees[10];
int i;

//fill array with data
for(i = 0; i < 10; i++)
{
cout << 'enter month of last vacation for this employee" << endl;
cin >> employees[i].lastVacationDay.month;
//etc. for day of last Vacation.

//convert Date data to sortDate to facilitate sorting
employees[i].convertDate(lastVacationDay);
}

//do bubble sort on employee[i].lastVacationDay.sortDate here

//display sorted array here

return0;
}