예제 #1
0
        public void QuickSort(CompareDelegate compareMethod) // Uses a CompareDelegate method.
        {
            int            i;
            T              pivot;
            GArrayList <T> leftList  = new GArrayList <T>();
            GArrayList <T> rightList = new GArrayList <T>();

            if (this.count < 100)
            {
                this.SelectionSort(compareMethod);
            }
            else
            {
                pivot = this[1];
                for (i = 2; i <= this.count; i++)
                {
                    if (this[i].CompareTo(pivot) < 0)
                    {
                        leftList.Add(this[i]);
                    }
                    else
                    {
                        rightList.Add(this[i]);
                    }
                }
                leftList.Add(pivot);
                leftList.QuickSort(compareMethod);
                rightList.QuickSort(compareMethod);
                this.Merge(leftList, rightList);
            }
        }
예제 #2
0
        public void QuickSort() // Uses the IComparable<T> CompareTo() method.
        {
            int            i;
            T              pivot;
            GArrayList <T> leftList  = new GArrayList <T>();
            GArrayList <T> rightList = new GArrayList <T>();

            if (this.count < 100)
            {
                this.SelectionSort();
            }
            else
            {
                pivot = this[1];
                for (i = 2; i <= this.count; i++)
                {
                    if (this[i].CompareTo(pivot) <= 0)
                    {
                        leftList.Add(this[i]);
                    }
                    else
                    {
                        rightList.Add(this[i]);
                    }
                }
                leftList.Add(pivot);
                leftList.QuickSort();
                rightList.QuickSort();
                for (i = 1; i <= leftList.count; i++)
                {
                    this[i] = leftList[i];
                }
                for (i = 1; i <= rightList.count; i++)
                {
                    this[leftList.count + i] = rightList[i];
                }
                //this.Clear();
                //for (i=1; i<=leftList.count; i++)
                //  this.Add(leftList[i]);
                //for (i=1; i<=rightList.count; i++)
                //  this.Add(rightList[i]);
            }
        }
예제 #3
0
        public void QuickSort(CompareDelegate compareMethod, BackgroundWorker bgWorker) // Uses a CompareDelegate method.
        {
            int            i;
            T              pivot;
            GArrayList <T> leftList  = new GArrayList <T>();
            GArrayList <T> rightList = new GArrayList <T>();

            if (!bgWorker.CancellationPending)
            {
                if (this.count < 100)
                {
                    this.SelectionSort(compareMethod, bgWorker);
                }
                else
                {
                    pivot = this[1];
                    for (i = 2; i <= this.count; i++)
                    {
                        if (compareMethod(this[i], pivot) <= 0)
                        {
                            leftList.Add(this[i]);
                        }
                        else
                        {
                            rightList.Add(this[i]);
                        }
                    }
                    leftList.Add(pivot);
                    leftList.QuickSort(compareMethod, bgWorker);
                    rightList.QuickSort(compareMethod, bgWorker);
                    for (i = 1; i <= leftList.count; i++)
                    {
                        this[i] = leftList[i];
                    }
                    for (i = 1; i <= rightList.count; i++)
                    {
                        this[leftList.count + i] = rightList[i];
                    }
                }
            }
        }