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 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 void SortHeap <T>( this ListIterator <T> first, ListIterator <T> last, Func <T, T, bool> comp ) { while (first.Distance(last) > 1) { last = last.GetPrev(); Swap(first, last); AdjustHeap(first.List, first.Index, first.Index, last.Index, comp); } }
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 void PopHeap <T>( this ListIterator <T> first, ListIterator <T> last, Func <T, T, bool> comp ) { if (first.Distance(last) < 2) { return; } last = last.GetPrev(); Swap(first, last); AdjustHeap(first.List, first.Index, first.Index, last.Index, comp); }
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); }