public static void Sort <T>( this ListIterator <T> first, ListIterator <T> last, Func <T, T, bool> comp ) { // Quicksort if (first.IsEqual(last)) { return; } var sep = first; for (var i = first.GetNext(); i.NotEqual(last); i = i.GetNext()) { if (comp(i.GetCurrent(), first.GetCurrent())) { sep = sep.GetNext(); sep.Swap(i); } } first.Swap(sep); first.Sort(sep, comp); sep.GetNext().Sort(last, comp); }
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 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; } } }