[FGFS-JAN14]How to keep connection between arrival and departure timings if I have to sort one of them?

Can anyone please explain the algorithm in detail…and
provide the code in C…?Here my doubt is …I am scanning the arriving times,departure times and preferred places in three different arrays…if I had sorted anyone of them,I would have lost the connection between three of them…How can I get rid of this…?
Thanks in advance…!!!

2 Likes

You can use struct and sort the whole struct using compare function
e.g.


void comp(struct node a,struct node b)
{
    return a.arr < b.arr;   //this will sort the structs according to arrival time.
}
struct node
{
   int arr,dep,pref;
};
node a[1000];
sort(a,a+n,comp);

2 Likes

thanq u @rahul_nexus

Use can use pair in the stl library of c++ . You can store them as a pair of number and then sort them , sorting will be done on the basis of first number . You can access elements by using variable.first and variable.second .

pair<int,int> a;
cin>>a.first>>a.second;
sort(a,a+n)
3 Likes

thanq u @the65bit

//