public static ArrayIterator <T> SetDifference <T>( this ArrayIterator <T> first1, ArrayIterator <T> last1, ArrayIterator <T> first2, ArrayIterator <T> last2, ArrayIterator <T> result, Func <T, T, bool> comp ) { while (first1.NotEqual(last1) && first2.NotEqual(last2)) { if (comp(first1.GetCurrent(), first2.GetCurrent())) { result.SetCurrent(first1.GetCurrent()); result = result.GetNext(); first1 = first1.GetNext(); } else if (comp(first2.GetCurrent(), first1.GetCurrent())) { first2 = first2.GetNext(); } else { first1 = first1.GetNext(); first2 = first2.GetNext(); } } return(first1.Copy(last1, result)); }
public static ArrayIterator <T> Merge <T>( this ArrayIterator <T> first1, ArrayIterator <T> last1, ArrayIterator <T> first2, ArrayIterator <T> last2, ArrayIterator <T> result, Func <T, T, bool> comp ) { while (true) { if (first1.IsEqual(last1)) { return(first2.Copy(last2, result)); } if (first2.IsEqual(last2)) { return(first1.Copy(last1, result)); } if (comp(first2.GetCurrent(), first1.GetCurrent())) { result.SetCurrent(first2.GetCurrent()); first2 = first2.GetNext(); } else { result.SetCurrent(first1.GetCurrent()); first1 = first1.GetNext(); } result = result.GetNext(); } }