Esempio n. 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);
            }
        }
Esempio n. 2
0
        public void MergeSort(CompareDelegate compareMethod, BackgroundWorker bgWorker) // Uses a CompareDelegate method to accomplish merge step.
        {
            int            i, midPos;
            GArrayList <T> leftList  = new GArrayList <T>();
            GArrayList <T> rightList = new GArrayList <T>();

            if (!bgWorker.CancellationPending)
            {
                if (this.count < 100)
                {
                    this.SelectionSort(compareMethod, bgWorker);
                }
                else
                {
                    midPos = (1 + this.count) / 2;
                    for (i = 1; i <= midPos; i++)
                    {
                        leftList.Add(this[i]);
                    }
                    for (i = midPos + 1; i <= this.count; i++)
                    {
                        rightList.Add(this[i]);
                    }
                    leftList.MergeSort(compareMethod, bgWorker);
                    rightList.MergeSort(compareMethod, bgWorker);
                    this.Merge(leftList, rightList, compareMethod);
                }
            }
        }
Esempio n. 3
0
        public void MergeSort() // Uses the IComparable<T> CompareTo() method to accomplish merge step.
        {
            int            i, midPos;
            GArrayList <T> leftList  = new GArrayList <T>();
            GArrayList <T> rightList = new GArrayList <T>();

            if (this.count < 100)
            {
                this.SelectionSort();
            }
            else
            {
                midPos = (1 + this.count) / 2;
                for (i = 1; i <= midPos; i++)
                {
                    leftList.Add(this[i]);
                }
                for (i = midPos + 1; i <= this.count; i++)
                {
                    rightList.Add(this[i]);
                }
                leftList.MergeSort();
                rightList.MergeSort();
                this.Merge(leftList, rightList);
            }
        }
Esempio n. 4
0
        public static GArrayList <T> operator+(GArrayList <T> list1, GArrayList <T> list2)
        {
            GArrayList <T> returnList = list1.Clone();

            foreach (T data in list2)
            {
                returnList.Add(data);
            }
            return(returnList);
        }
Esempio n. 5
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]);
            }
        }
Esempio n. 6
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];
                    }
                }
            }
        }
Esempio n. 7
0
        private void IncreaseCapacity()
        {
            GArrayList <T> tempList = new GArrayList <T>(2 * this.capacity);

            foreach (T data in this)
            {
                tempList.Add(data);
            }
            this.capacity = tempList.capacity;
            this.count    = tempList.count;
            this.items    = tempList.items;
        }
Esempio n. 8
0
        public static GArrayList <T> operator-(GArrayList <T> list1, GArrayList <T> list2)
        {
            GArrayList <T> returnList = new GArrayList <T>();

            foreach (T data in list1)
            {
                if (list2.LinearSearch(data) < 0)
                {
                    returnList.Add(data);
                }
            }
            return(returnList);
        }