Thread: sorting

  1. #1
    adrive
    Guest

    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!

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    203
    a long int allows easy sorting in chronological order using this format: yyyymmdd

    this is (year * 10000) + (month * 100) + day

  3. #3
    adrive
    Guest
    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

  4. #4
    Unregistered
    Guest
    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;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 06-11-2009, 11:27 AM
  2. Need help with linked list sorting function
    By Jaggid1x in forum C Programming
    Replies: 6
    Last Post: 06-02-2009, 02:14 AM
  3. sorting structure members using pointers
    By robstr12 in forum C Programming
    Replies: 5
    Last Post: 07-25-2005, 05:50 PM
  4. Still Needing Help : selection sorting
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 10-14-2001, 08:41 PM
  5. selection sorting
    By Unregistered in forum C Programming
    Replies: 5
    Last Post: 10-13-2001, 08:05 PM