public static ListIterator <T> Merge <T>( this ListIterator <T> first1, ListIterator <T> last1, ListIterator <T> first2, ListIterator <T> last2, ListIterator <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(); } }
public static ListIterator <T> UniqueCopy <T>( this ListIterator <T> first, ListIterator <T> last, ListIterator <T> result, Func <T, T, bool> pred ) { if (first.IsEqual(last)) { return(last); } result.SetCurrent(first.GetCurrent()); while ((first = first.GetNext()).NotEqual(last)) { var val = first.GetCurrent(); if (pred(result.GetCurrent(), val) == false) { result = result.GetNext(); result.SetCurrent(val); } } result = result.GetNext(); return(result); }
public static void PartitionCopy <T>( this ListIterator <T> first, ListIterator <T> last, ListIterator <T> resultTrue, ListIterator <T> resultFalse, Func <T, bool> pred, out ListIterator <T> outResultTrue, out ListIterator <T> outResultFalse ) { while (first.NotEqual(last)) { if (pred(first.GetCurrent())) { resultTrue.SetCurrent(first.GetCurrent()); resultTrue = resultTrue.GetNext(); } else { resultFalse.SetCurrent(first.GetCurrent()); resultFalse = resultFalse.GetNext(); } first = first.GetNext(); } outResultTrue = resultTrue; outResultFalse = resultFalse; }
public static void Swap <T>(this ListIterator <T> a, ListIterator <T> b) { var temp = a.GetCurrent(); a.SetCurrent(b.GetCurrent()); b.SetCurrent(temp); }
public static ListIterator <T> SetDifference <T>( this ListIterator <T> first1, ListIterator <T> last1, ListIterator <T> first2, ListIterator <T> last2, ListIterator <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 void PushHeap <T>( this ListIterator <T> first, ListIterator <T> last, Func <T, T, bool> comp ) { if (first.Distance(last) < 2) { return; } last = last.GetPrev(); var temp = last.GetCurrent(); var parent = first.GetAdvanced((first.Distance(last) - 1) / 2); while (first.Distance(last) > 0 && comp(parent.GetCurrent(), temp)) { last.SetCurrent(parent.GetCurrent()); last = parent; parent = first.GetAdvanced((first.Distance(last) - 1) / 2); } last.SetCurrent(temp); }
public static ListIterator <T> ReverseCopy <T>( this ListIterator <T> first, ListIterator <T> last, ListIterator <T> result ) { while (first.NotEqual(last)) { last = last.GetPrev(); result.SetCurrent(last.GetCurrent()); result = result.GetNext(); } return(result); }
public static ListIterator <T> CopyBackward <T>( this ListIterator <T> first, ListIterator <T> last, ListIterator <T> result ) { while (last.NotEqual(first)) { result = result.GetPrev(); last = last.GetPrev(); result.SetCurrent(last.GetCurrent()); } return(result); }
public static ListIterator <T> Transform <T>( this ListIterator <T> first1, ListIterator <T> last1, ListIterator <T> result, Func <T, T> op ) { while (first1.NotEqual(last1)) { result.SetCurrent(op(first1.GetCurrent())); result = result.GetNext(); first1 = first1.GetNext(); } return(result); }
public static ListIterator <T> CopyN <T>( this ListIterator <T> first, int n, ListIterator <T> result ) { while (n > 0) { result.SetCurrent(first.GetCurrent()); result = result.GetNext(); first = first.GetNext(); n--; } return(result); }
public static ListIterator <T> ReplaceCopyIf <T>( this ListIterator <T> first, ListIterator <T> last, ListIterator <T> result, Func <T, bool> pred, T newValue ) { while (first.NotEqual(last)) { result.SetCurrent(pred(first.GetCurrent()) ? newValue : first.GetCurrent()); first = first.GetNext(); result = result.GetNext(); } return(result); }
public static void ReplaceIf <T>( this ListIterator <T> first, ListIterator <T> last, Func <T, bool> pred, T newValue ) { while (first.NotEqual(last)) { if (pred(first.GetCurrent())) { first.SetCurrent(newValue); } first = first.GetNext(); } }
public static ListIterator <T> CopyIf <T>( this ListIterator <T> first, ListIterator <T> last, ListIterator <T> result, Func <T, bool> pred ) { while (first.NotEqual(last)) { if (pred(first.GetCurrent())) { result.SetCurrent(first.GetCurrent()); result = result.GetNext(); } first = first.GetNext(); } return(result); }