Пример #1
0
 public static ArrayIterator <T> Partition <T>(
     this ArrayIterator <T> first,
     ArrayIterator <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);
 }
Пример #2
0
 public static void Reverse <T>(this ArrayIterator <T> first, ArrayIterator <T> last)
 {
     while ((first.NotEqual(last)) && (first.NotEqual((last = last.GetPrev()))))
     {
         first.Swap(last);
         first = first.GetNext();
     }
 }
Пример #3
0
 public static void SortHeap <T>(
     this ArrayIterator <T> first,
     ArrayIterator <T> last,
     Func <T, T, bool> comp
     )
 {
     while (first.Distance(last) > 1)
     {
         last = last.GetPrev();
         Swap(first, last);
         AdjustHeap(first.Array, first.Index, first.Index, last.Index, comp);
     }
 }
Пример #4
0
 public static ArrayIterator <T> ReverseCopy <T>(
     this ArrayIterator <T> first,
     ArrayIterator <T> last,
     ArrayIterator <T> result
     )
 {
     while (first.NotEqual(last))
     {
         last = last.GetPrev();
         result.SetCurrent(last.GetCurrent());
         result = result.GetNext();
     }
     return(result);
 }
Пример #5
0
 public static ArrayIterator <T> CopyBackward <T>(
     this ArrayIterator <T> first,
     ArrayIterator <T> last,
     ArrayIterator <T> result
     )
 {
     while (last.NotEqual(first))
     {
         result = result.GetPrev();
         last   = last.GetPrev();
         result.SetCurrent(last.GetCurrent());
     }
     return(result);
 }
Пример #6
0
 public static void PopHeap <T>(
     this ArrayIterator <T> first,
     ArrayIterator <T> last,
     Func <T, T, bool> comp
     )
 {
     if (first.Distance(last) < 2)
     {
         return;
     }
     last = last.GetPrev();
     Swap(first, last);
     AdjustHeap(first.Array, first.Index, first.Index, last.Index, comp);
 }
Пример #7
0
        public static void PushHeap <T>(
            this ArrayIterator <T> first,
            ArrayIterator <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);
        }