Your example is complex. First I will formulate and solve a simpler problem, then I use the same method to solve your original problem.
I want to split the list of numbers into adjacent groups of even and odd numbers. For example, given the list of 2,2,4,3,6,2 , I would divide it into three groups [2,2,4], [3], [6,2]
This can be done using the GroupAdjacentBy method .
> var numbers = new List<int>{2,2,4,3,6,2}; > numbers.GroupAdjacentBy(x => x % 2) [[2,2,4], [3], [6,2]]
To solve your problem, simply replace the even classification function above with your classification function:
> var points = new List<int>{-180,180}; > var f = new Func<int,int>(x => points.BinarySearch(x)); > var numbers = new List<int>{6,-50,100,190,200,20}; > numbers.GroupAdjacentBy(f) [[6,-50,100], [190,200], [20]]