public static void Reverse <T>(this ListIterator <T> first, ListIterator <T> last) { while ((first.NotEqual(last)) && (first.NotEqual((last = last.GetPrev())))) { first.Swap(last); first = first.GetNext(); } }
public static ListIterator <T> SearchN <T>( this ListIterator <T> first, ListIterator <T> last, int count, T val, Func <T, T, bool> pred ) { var limit = first.GetAdvanced(first.Distance(last) - count); while (first.NotEqual(limit)) { var it = first; var i = 0; while (pred(val, it.GetCurrent())) { it = it.GetNext(); if (++i == count) { return(first); } } first = first.GetNext(); } return(last); }
public static ListIterator <T> Search <T>( this ListIterator <T> first1, ListIterator <T> last1, ListIterator <T> first2, ListIterator <T> last2, Func <T, T, bool> pred ) { if (first2.IsEqual(last2)) { return(first1); } while (first1.NotEqual(last1)) { var it1 = first1; var it2 = first2; while (pred(it1.GetCurrent(), it2.GetCurrent())) { it1 = it1.GetNext(); it2 = it2.GetNext(); if (it2.IsEqual(last2)) { return(first1); } if (it1.IsEqual(last1)) { return(last1); } } first1 = first1.GetNext(); } return(last1); }
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 ListIterator <T> Partition <T>( this ListIterator <T> first, ListIterator <T> last, Func <T, bool> pred ) { while (first.NotEqual(last)) { while (pred(first.GetCurrent())) { first = first.GetNext(); if (first.IsEqual(last)) { return(first); } } do { last = last.GetPrev(); if (first.IsEqual(last)) { return(first); } } while (pred(last.GetCurrent()) == false); first.Swap(last); first = first.GetNext(); } return(first); }
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 bool BinarySearch <T>( this ListIterator <T> first, ListIterator <T> last, T val, Func <T, T, bool> comp ) { first = first.LowerBound(last, val, comp); return(first.NotEqual(last) && comp(val, first.GetCurrent()) == false); }
public static bool IsPartitioned <T>( this ListIterator <T> first, ListIterator <T> last, Func <T, bool> pred ) { while (first.NotEqual(last) && pred(first.GetCurrent())) { first = first.GetNext(); } while (first.NotEqual(last)) { if (pred(first.GetCurrent())) { return(false); } first = first.GetNext(); } return(true); }
public static void ForEach <T>( this ListIterator <T> first, ListIterator <T> last, Action <T> callback ) { while (first.NotEqual(last)) { callback(first.GetCurrent()); first = first.GetNext(); } }
public static ListIterator <T> SwapRanges <T>( this ListIterator <T> first1, ListIterator <T> last1, ListIterator <T> first2 ) { while (first1.NotEqual(last1)) { Swap(first1, first2); first1 = first1.GetNext(); first2 = first2.GetNext(); } return(first2); }
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> FindIf <T>( this ListIterator <T> first, ListIterator <T> last, Func <T, bool> pred ) { while (first.NotEqual(last)) { if (pred(first.GetCurrent())) { return(first); } first = first.GetNext(); } return(last); }
public static bool AllOf <T>( this ListIterator <T> first, ListIterator <T> last, Func <T, bool> pred ) { while (first.NotEqual(last)) { if (pred(first.GetCurrent()) == false) { return(false); } first = first.GetNext(); } return(true); }
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); }
public static int CountIf <T>( this ListIterator <T> first, ListIterator <T> last, Func <T, bool> pred ) { var count = 0; while (first.NotEqual(last)) { if (pred(first.GetCurrent())) { count++; } first = first.GetNext(); } return(count); }
public static bool Equal <T>( this ListIterator <T> first1, ListIterator <T> last1, ListIterator <T> first2, Func <T, T, bool> pred ) { while (first1.NotEqual(last1)) { if (pred(first1.GetCurrent(), first2.GetCurrent()) == false) { return(false); } first1 = first1.GetNext(); first2 = first2.GetNext(); } return(true); }
public static ListIterator <T> FindFirstOf <T>( this ListIterator <T> first1, ListIterator <T> last1, ListIterator <T> first2, ListIterator <T> last2, Func <T, T, bool> pred ) { while (first1.NotEqual(last1)) { for (var it = first2; it.NotEqual(last2); it = it.GetNext()) { if (pred(it.GetCurrent(), first1.GetCurrent())) { return(first1); } } first1 = first1.GetNext(); } return(last1); }
public static void Mismatch <T>( this ListIterator <T> first1, ListIterator <T> last1, ListIterator <T> first2, Func <T, T, bool> pred, out ListIterator <T> mismatch1, out ListIterator <T> mismatch2 ) { while (first1.NotEqual(last1)) { if (pred(first1.GetCurrent(), first2.GetCurrent()) == false) { break; } first1 = first1.GetNext(); first2 = first2.GetNext(); } mismatch1 = first1; mismatch2 = first2; }
public static ListIterator <T> AdjacentFind <T>( this ListIterator <T> first, ListIterator <T> last, Func <T, T, bool> pred ) { if (first.NotEqual(last)) { var next = first; next = next.GetNext(); while (next.NotEqual(last)) { if (pred(first.GetCurrent(), next.GetCurrent())) { return(first); } first = first.GetNext(); next = next.GetNext(); } } return(last); }
public static bool Includes <T>( this ListIterator <T> first1, ListIterator <T> last1, ListIterator <T> first2, ListIterator <T> last2, Func <T, T, bool> comp ) { while (first2.NotEqual(last2)) { if ((first1.IsEqual(last1)) || comp(first2.GetCurrent(), first1.GetCurrent())) { return(false); } if (comp(first1.GetCurrent(), first2.GetCurrent()) == false) { first2 = first2.GetNext(); } first1 = first1.GetNext(); } return(true); }
public static bool LexicographicalCompare <T>( this ListIterator <T> first1, ListIterator <T> last1, ListIterator <T> first2, ListIterator <T> last2, Func <T, T, bool> comp ) { while (first1.NotEqual(last1)) { if (first2.IsEqual(last2) || comp(first2.GetCurrent(), first1.GetCurrent())) { return(false); } else if (comp(first1.GetCurrent(), first2.GetCurrent())) { return(true); } first1 = first1.GetNext(); first2 = first2.GetNext(); } return(first2.NotEqual(last2)); }
public static void Rotate <T>( this ListIterator <T> first, ListIterator <T> middle, ListIterator <T> last ) { var next = middle; while (first.NotEqual(last)) { first.Swap(next); first = first.GetNext(); next = next.GetNext(); if (next.IsEqual(last)) { next = middle; } else if (first.IsEqual(middle)) { middle = next; } } }