示例#1
0
        public static void Sort <T>(
            this ArrayIterator <T> first,
            ArrayIterator <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);
        }
示例#2
0
 public static void NthElement <T>(
     this ArrayIterator <T> first,
     ArrayIterator <T> nth,
     ArrayIterator <T> last,
     Func <T, T, bool> comp
     )
 {
     // TODO find a faster algorithm that doesn't create any garbage
     first.Sort(last, comp);
 }
示例#3
0
 public static void PartialSort <T>(
     this ArrayIterator <T> first,
     ArrayIterator <T> middle,
     ArrayIterator <T> last,
     Func <T, T, bool> comp
     )
 {
     // TODO find a faster algorithm that doesn't create any garbage
     first.Sort(last, comp);
 }