コード例 #1
0
        /// <summary>Swap items.</summary>
        /// <param name="items">The items.</param>
        /// <param name="x">The x.</param>
        /// <param name="w">The w.</param>
        private void Swap(VisualListViewItemCollection items, int x, int w)
        {
            VisualListViewItem _tempItem;

            _tempItem = items[x];
            items[x]  = items[x];
            items[w]  = _tempItem;
        }
コード例 #2
0
        /// <summary>The sort.</summary>
        /// <param name="items">The items.</param>
        /// <param name="low_0">The low.</param>
        /// <param name="high_0">The high.</param>
        public void Sort(VisualListViewItemCollection items, int low_0, int high_0)
        {
            int lo = low_0;
            int hi = high_0;

            if (lo >= hi)
            {
                return;
            }

            int mid = (lo + hi) / 2;

            Sort(items, lo, mid);
            Sort(items, mid + 1, hi);

            int end_lo   = mid;
            int start_hi = mid + 1;

            while ((lo <= end_lo) && (start_hi <= hi))
            {
                if (StopRequested)
                {
                    return;
                }

                if (CompareItems(items[lo], items[start_hi], CompareDirection.LessThan))
                {
                    lo++;
                }
                else
                {
                    VisualListViewItem visualListViewItem = items[start_hi];
                    for (int k = start_hi - 1; k >= lo; k--)
                    {
                        items[k + 1] = items[k];
                    }

                    items[lo] = visualListViewItem;
                    lo++;
                    end_lo++;
                    start_hi++;
                }
            }
        }
コード例 #3
0
        /// <summary>The list-view insertion sort.</summary>
        /// <param name="items">The items.</param>
        /// <param name="low0">The low.</param>
        /// <param name="high0">The high.</param>
        public void LVInsertionSort(VisualListViewItemCollection items, int low0, int high0)
        {
            int w;
            VisualListViewItem _tempItem;

            for (int x = low0; x <= high0; x++)
            {
                _tempItem = items[x];
                w         = x;

                while ((w > low0) && CompareItems(items[w - 1], _tempItem, CompareDirection.GreaterThan))
                {
                    items[w] = items[w - 1];
                    w--;
                }

                items[w] = _tempItem;
            }
        }
コード例 #4
0
 /// <summary>Sort the items collection.</summary>
 /// <param name="items">The items.</param>
 public void Sort(VisualListViewItemCollection items)
 {
     QuickSort(items, 0, items.Count - 1);
     LVInsertionSort(items, 0, items.Count - 1);
 }
コード例 #5
0
        /// <summary>Quick sort the items collection.</summary>
        /// <param name="items">The items.</param>
        /// <param name="left">The left.</param>
        /// <param name="right">The right.</param>
        public void QuickSort(VisualListViewItemCollection items, int left, int right)
        {
            int w;
            int x;

            VisualListViewItem _tempItem;
            int med = 4;

            if (right - left > med)
            {
                w = (right + left) / 2;

                if (CompareItems(items[left], items[w], CompareDirection.GreaterThan))
                {
                    Swap(items, left, w);
                }

                if (CompareItems(items[left], items[right], CompareDirection.GreaterThan))
                {
                    Swap(items, left, right);
                }

                if (CompareItems(items[w], items[right], CompareDirection.GreaterThan))
                {
                    Swap(items, w, right);
                }

                x = right - 1;
                Swap(items, w, x);
                w         = left;
                _tempItem = items[x];

                while (true)
                {
                    while (CompareItems(items[++w], _tempItem, CompareDirection.LessThan))
                    {
                    }

                    while (CompareItems(items[--x], _tempItem, CompareDirection.GreaterThan))
                    {
                    }

                    if (x < w)
                    {
                        break;
                    }

                    Swap(items, w, x);

                    if (_stopRequested)
                    {
                        return;
                    }
                }

                Swap(items, w, right - 1);

                QuickSort(items, left, x);
                QuickSort(items, w + 1, right);
            }
        }