You are not logged in. Please login at to post your questions!


[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...!!!

asked 12 Jul '14, 18:03

neal95's gravatar image

accept rate: 10%

edited 12 Jul '14, 18:33

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

rahul_nexus's gravatar image

accept rate: 13%

thanq u @rahul_nexus

(12 Jul '14, 19:46) neal953★

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;

answered 12 Jul '14, 21:41

the65bit's gravatar image

accept rate: 13%

thanq u @the65bit

(13 Jul '14, 14:13) neal953★
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • 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:


question asked: 12 Jul '14, 18:03

question was seen: 1,438 times

last updated: 13 Jul '14, 14:13