Possible Duplicate:
c++ sort with structs
I am trying to figure out how to sort an array of structs on a specific variable in the struct held within the array. Here is my code:
struct Process{
int pid;
int burst;
int arrival;
};
int main(int argc, char *argv[]){
// The number of processes
int numProcesses = 3;
//Create an array that holds 10 Process structs
Process *arrayOfProcesses = new Process[numProcesses];
// Puts values in each pid, burst, and arrival
arrayOfProcesses[0].pid = 0;
arrayOfProcesses[0].burst = 8;
arrayOfProcesses[0].arrival = 2;
arrayOfProcesses[1].pid = 1;
arrayOfProcesses[1].burst = 12;
arrayOfProcesses[1].arrival = 3;
arrayOfProcesses[2].pid = 2;
arrayOfProcesses[2].burst = 4;
arrayOfProcesses[2].arrival = 1;
// Sort the array based on the arrival time
// Help! :)
}
I would really like to be able to sort the array in my code on the arrival time. I've simplified my code to give you a general idea of what I'm trying to accomplish. In my actual code,t he array is filled dynamically from information read in by a file. I know that using a List or even a Vector would be better options, but I am determined to figure this out using arrays.
Any help with sorting this would be appreciated! :)