예제 #1
0
        private int Separate(int left, int right)
        {
            int i     = left;
            int j     = right - 1;
            int pivot = collection[right];

            do
            {
                SortCancellationToken.ThrowIfCancellationRequested();
                while (collection[i].CompareTo(pivot) <= 0 && i.CompareTo(right) < 0)
                {
                    i++;
                }

                while (collection[j].CompareTo(pivot) > 0 && j.CompareTo(left) > 0)
                {
                    j--;
                }

                if (i.CompareTo(j) < 0)
                {
                    SwapIndex(i, j);
                    OnReportProgress();
                }
            } while (i.CompareTo(j) < 0);

            SwapIndex(i, right);
            OnReportProgress();

            return(i);
        }
예제 #2
0
        /// <summary>
        /// Sort´s the collection
        /// </summary>
        /// <param name="input">collection to be sorted</param>
        public override void Sort(IList <int> input)
        {
            collection = new List <int>(input);
            OnReportProgress();

            for (int i = 1; i < collection.Count; i++)
            {
                int index = collection[i];
                int j     = i;

                while (j > 0 && collection[j - 1].CompareTo(index) > 0)
                {
                    collection[j] = collection[j - 1];
                    j--;
                }
                collection[j] = index;
                OnReportProgress();
                SortCancellationToken.ThrowIfCancellationRequested();
            }
        }
예제 #3
0
        /// <summary>
        /// Sort´s the collection
        /// </summary>
        /// <param name="input">collection to be sorted</param>
        public override void Sort(IList <int> input)
        {
            collection = new List <int>(input);
            OnReportProgress();

            for (int i = collection.Count - 1; i >= 0; i--)
            {
                for (int j = 1; j <= i; j++)
                {
                    if (collection[j - 1].CompareTo(collection[j]) > 0)
                    {
                        SwapIndex(j - 1, j);
                    }
                    SortCancellationToken.ThrowIfCancellationRequested();
                }
                OnReportProgress();

                SortCancellationToken.ThrowIfCancellationRequested();
            }
        }
예제 #4
0
        /// <summary>
        /// Sort´s the collection
        /// </summary>
        /// <param name="input">collection to be sorted</param>
        public override void Sort(IList <int> input)
        {
            collection = new List <int>(input);
            OnReportProgress();

            for (int i = 0; i < collection.Count - 1; i++)
            {
                int minimum = i;
                for (int j = i + 1; j < collection.Count; j++)
                {
                    if (collection[j].CompareTo(collection[minimum]) < 0)
                    {
                        minimum = j;
                    }
                    SortCancellationToken.ThrowIfCancellationRequested();
                }

                SwapIndex(minimum, i);
                OnReportProgress();
            }
        }
예제 #5
0
        private void Merge(int[] data, int left, int middle, int middle1, int right)
        {
            int oldPosition = left;
            int size        = right - left + 1;

            int[] tmpData = new int[size];
            int   i       = 0;

            while (left.CompareTo(middle) <= 0 && middle1.CompareTo(right) <= 0)
            {
                if (data[left].CompareTo(data[middle1]) <= 0)
                {
                    tmpData[i++] = data[left++];
                }
                else
                {
                    tmpData[i++] = data[middle1++];
                }
                SortCancellationToken.ThrowIfCancellationRequested();
            }

            if (left.CompareTo(middle) > 0)
            {
                for (int j = middle1; j <= right; j++)
                {
                    tmpData[i++] = data[middle1++];
                }
            }
            else
            {
                for (int j = left; j <= middle; j++)
                {
                    tmpData[i++] = data[left++];
                }
            }
            Array.Copy(tmpData, 0, data, oldPosition, size);
            OnReportProgress(data);
            SortCancellationToken.ThrowIfCancellationRequested();
        }