public static void EqualRange <T>( this ListIterator <T> first, ListIterator <T> last, T val, Func <T, T, bool> comp, out ListIterator <T> lower, out ListIterator <T> upper ) { lower = first.LowerBound(last, val, comp); upper = lower.UpperBound(last, val, comp); }
public static void InplaceMerge <T>( this ListIterator <T> first, ListIterator <T> middle, ListIterator <T> last, Func <T, T, bool> comp ) { if (first.Index >= middle.Index || middle.Index >= last.Index) { return; } if (last.Index - first.Index == 2) { if (comp(middle.GetCurrent(), first.GetCurrent())) { Swap(first, middle); } return; } ListIterator <T> firstCut; ListIterator <T> secondCut; if (middle.Index - first.Index > last.Index - middle.Index) { firstCut = first.GetAdvanced(first.Distance(middle) / 2); secondCut = middle.LowerBound(last, firstCut.GetCurrent(), comp); } else { secondCut = middle.GetAdvanced(middle.Distance(last) / 2); firstCut = first.UpperBound(middle, secondCut.GetCurrent(), comp); } Rotate(firstCut, middle, secondCut); middle = firstCut.GetAdvanced(middle.Distance(secondCut)); InplaceMerge(first, firstCut, middle, comp); InplaceMerge(middle, secondCut, last, comp); }