×

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

 2 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...!!! asked 12 Jul '14, 18:03 3★neal95 318●7●12 accept rate: 10%

 2 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);  answered 12 Jul '14, 18:53 774●1●9●23 accept rate: 13% thanq u @rahul_nexus (12 Jul '14, 19:46) neal953★
 3 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 a; cin>>a.first>>a.second; sort(a,a+n)  answered 12 Jul '14, 21:41 4★the65bit 1.1k●10●13●28 accept rate: 13% thanq u @the65bit (13 Jul '14, 14:13) neal953★
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×801
×51
×3

question asked: 12 Jul '14, 18:03

question was seen: 1,443 times

last updated: 13 Jul '14, 14:13