Wednesday, 15 June 2011

java - Compare Data within List with every other Index -



java - Compare Data within List with every other Index -

class { public datetime start; public datetime end; }

hi have list of objects of size , want compare each object other objects in list if overlap, thought go foreach , run through each object , compare whole list. slow , resource hogging. better?

a linearithmic (o(nlogn)) solution sort objects startpoint , compare startpoint of every object endpoint of 1 before it. if startpoint of object k lower or equal endpoint of object k-1, have overlap. otherwise, don't.

i'm not sure c# in java implementing comparable interface , using arrays.sort(). i'd wrote illustration code i'm on mobile.

java c# algorithm list

No comments:

Post a Comment