Exemplo n.º 1
0
        private static int PickPivotAndPartition(T[] keys, int lo, int hi)
        {
            int index = lo + (hi - lo) / 2;

            GenericArraySortHelper <T> .SwapIfGreaterWithItems(keys, lo, index);

            GenericArraySortHelper <T> .SwapIfGreaterWithItems(keys, lo, hi);

            GenericArraySortHelper <T> .SwapIfGreaterWithItems(keys, index, hi);

            T obj = keys[index];

            GenericArraySortHelper <T> .Swap(keys, index, hi - 1);

            int i = lo;
            int j = hi - 1;

            while (i < j)
            {
                if ((object)obj == null)
                {
                    do
                    {
                        ;
                    }while (i < hi - 1 && (object)keys[++i] == null);
                    while (j > lo && (object)keys[--j] != null)
                    {
                        ;
                    }
                }
                else
                {
                    do
                    {
                        ;
                    }while (obj.CompareTo(keys[++i]) > 0);
                    while (obj.CompareTo(keys[--j]) < 0)
                    {
                        ;
                    }
                }
                if (i < j)
                {
                    GenericArraySortHelper <T> .Swap(keys, i, j);
                }
                else
                {
                    break;
                }
            }
            GenericArraySortHelper <T> .Swap(keys, i, hi - 1);

            return(i);
        }
        // Token: 0x06003A30 RID: 14896 RVA: 0x000DCA48 File Offset: 0x000DAC48
        private static int PickPivotAndPartition(T[] keys, int lo, int hi)
        {
            int num = lo + (hi - lo) / 2;

            GenericArraySortHelper <T> .SwapIfGreaterWithItems(keys, lo, num);

            GenericArraySortHelper <T> .SwapIfGreaterWithItems(keys, lo, hi);

            GenericArraySortHelper <T> .SwapIfGreaterWithItems(keys, num, hi);

            T t = keys[num];

            GenericArraySortHelper <T> .Swap(keys, num, hi - 1);

            int i = lo;
            int j = hi - 1;

            while (i < j)
            {
                if (t == null)
                {
                    while (i < hi - 1 && keys[++i] == null)
                    {
                    }
                    while (j > lo)
                    {
                        if (keys[--j] == null)
                        {
                            break;
                        }
                    }
                }
                else
                {
                    while (t.CompareTo(keys[++i]) > 0)
                    {
                    }
                    while (t.CompareTo(keys[--j]) < 0)
                    {
                    }
                }
                if (i >= j)
                {
                    break;
                }
                GenericArraySortHelper <T> .Swap(keys, i, j);
            }
            GenericArraySortHelper <T> .Swap(keys, i, hi - 1);

            return(i);
        }
        // Token: 0x06003A31 RID: 14897 RVA: 0x000DCB18 File Offset: 0x000DAD18
        private static void Heapsort(T[] keys, int lo, int hi)
        {
            int num = hi - lo + 1;

            for (int i = num / 2; i >= 1; i--)
            {
                GenericArraySortHelper <T> .DownHeap(keys, i, num, lo);
            }
            for (int j = num; j > 1; j--)
            {
                GenericArraySortHelper <T> .Swap(keys, lo, lo + j - 1);

                GenericArraySortHelper <T> .DownHeap(keys, 1, j - 1, lo);
            }
        }
Exemplo n.º 4
0
        private static void Heapsort(T[] keys, int lo, int hi)
        {
            int n = hi - lo + 1;

            for (int i = n / 2; i >= 1; --i)
            {
                GenericArraySortHelper <T> .DownHeap(keys, i, n, lo);
            }
            for (int index = n; index > 1; --index)
            {
                T[] a   = keys;
                int i   = lo;
                int num = index;
                int j   = i + num - 1;
                GenericArraySortHelper <T> .Swap(a, i, j);

                GenericArraySortHelper <T> .DownHeap(keys, 1, index - 1, lo);
            }
        }
Exemplo n.º 5
0
        private static void Heapsort(TKey[] keys, TValue[] values, int lo, int hi)
        {
            int n = hi - lo + 1;

            for (int i = n / 2; i >= 1; --i)
            {
                GenericArraySortHelper <TKey, TValue> .DownHeap(keys, values, i, n, lo);
            }
            for (int index = n; index > 1; --index)
            {
                TKey[]   keys1   = keys;
                TValue[] values1 = values;
                int      i       = lo;
                int      num     = index;
                int      j       = i + num - 1;
                GenericArraySortHelper <TKey, TValue> .Swap(keys1, values1, i, j);

                GenericArraySortHelper <TKey, TValue> .DownHeap(keys, values, 1, index - 1, lo);
            }
        }