I ve to sort an array according to finish time and accordingly start time should be arranged, how can we do this using predefined function qsort. Both Start time and finish time, i ve considered it be in a structure ,
.here is the code..
#include<stdio.h>
#include<stdlib.h>
int compare (const void * a, const void * b)
{
return ( *(int*)a - *(int*)b );
}
struct time {
int start[100005];
int finish[100005];
}t;
int main() {
int n,i;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d%d",&t.start[i],&t.finish[i]);
qsort(t.finish,n,sizeof(int),compare);
for(i=0;i<n;i++)
printf("%d %d\n",t.start[i],t.finish[i]);
return 0;
}