Exemplo n.º 1
0
    /// <summary>
    /// List.Sort equivalent.
    /// </summary>
    ///

    void QuickSort(System.Comparison <T> comparer, int min, int max)
    {
        if (max - min < 1)
        {
            return;
        }
        int iKeyIndex = ((max + min) / 2);

        T key = buffer[iKeyIndex]; //假定关键词

        if (max - min == 1)
        {
            if (comparer.Invoke(key, buffer[max]) > 0)
            {
                buffer[min] = buffer[max];
                buffer[max] = key;
            }
            return;
        }

        int begin = min;
        int end   = max;

        for (int i = min; i <= max; i++)
        {
            if (iKeyIndex == i)
            {
                continue;
            }

            T refValue = buffer[i];

            int compare = comparer.Invoke(refValue, key);
            if (compare > 0)
            {
                tempbuffer[end] = refValue;
                end--;
            }
            else
            {
                tempbuffer[begin] = refValue;
                begin++;
            }
        }
        tempbuffer[begin] = key;

        for (int i = min; i <= max; i++)
        {
            buffer[i] = tempbuffer[i];
        }
        QuickSort(comparer, min, begin - 1);
        QuickSort(comparer, begin + 1, max);
    }
Exemplo n.º 2
0
        /// <summary>
        /// List.Sort equivalent.
        /// </summary>

        public void Sort(System.Comparison <T> comparer)
        {
            bool changed = true;

            while (changed)
            {
                changed = false;

                for (int i = 1; i < size; ++i)
                {
                    if (comparer.Invoke(buffer[i - 1], buffer[i]) > 0)
                    {
                        T temp = buffer[i];
                        buffer[i]     = buffer[i - 1];
                        buffer[i - 1] = temp;
                        changed       = true;
                    }
                }
            }
        }
Exemplo n.º 3
0
        static StackObject *Invoke_0(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 3);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.Object @y = (System.Object) typeof(System.Object).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
            System.Object @x = (System.Object) typeof(System.Object).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 3);
            System.Comparison <System.Object> instance_of_this_method = (System.Comparison <System.Object>) typeof(System.Comparison <System.Object>).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            var result_of_this_method = instance_of_this_method.Invoke(@x, @y);

            __ret->ObjectType = ObjectTypes.Integer;
            __ret->Value      = result_of_this_method;
            return(__ret + 1);
        }
Exemplo n.º 4
0
 public Locker(System.Comparison <T> sorter) : this()
 {
     _sortComparer = (ItemBox a, ItemBox b) => sorter.Invoke(a.Item, b.Item);
 }