Exemplo n.º 1
0
        private void swap(GLItemCollection items, int x, int w)
        {
            GLItem tmpItem;

            tmpItem  = items[x];
            items[x] = items[w];
            items[w] = tmpItem;
        }
Exemplo n.º 2
0
        public void QuickSort(GLItemCollection items, int vleft, int vright)
        {
            int    w, x;
            GLItem tmpItem;

            int Med = 4;

            if ((vright - vleft) > Med)
            {
                w = (vright + vleft) / 2;

                if (CompareItems(items[vleft], items[w], CompareDirection.GreaterThan))
                {
                    swap(items, vleft, w);
                }
                if (CompareItems(items[vleft], items[vright], CompareDirection.GreaterThan))
                {
                    swap(items, vleft, vright);
                }
                if (CompareItems(items[w], items[vright], CompareDirection.GreaterThan))
                {
                    swap(items, w, vright);
                }

                x = vright - 1;
                swap(items, w, x);
                w       = vleft;
                tmpItem = items[x];

                while (true)
                {
                    while (this.CompareItems(items[++w], tmpItem, CompareDirection.LessThan))
                    {
                        ;
                    }
                    while (this.CompareItems(items[--x], tmpItem, CompareDirection.GreaterThan))
                    {
                        ;
                    }

                    if (x < w)
                    {
                        break;
                    }

                    swap(items, w, x);

                    if (m_bStopRequested)
                    {
                        return;
                    }
                }
                swap(items, w, vright - 1);

                QuickSort(items, vleft, x);
                QuickSort(items, w + 1, vright);
            }
        }
Exemplo n.º 3
0
        public void sort(GLItemCollection 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
                {
                    GLItem T = items[start_hi];
                    for (int k = start_hi - 1; k >= lo; k--)
                    {
                        items[k + 1] = items[k];
                    }

                    items[lo] = T;
                    lo++;
                    end_lo++;
                    start_hi++;
                }
            }
        }
Exemplo n.º 4
0
        public void GLInsertionSort(GLItemCollection items, int nLow0, int nHigh0)
        {
            int w;

            GLItem tmpItem;

            for (int x = nLow0 + 1; x <= nHigh0; x++)
            {
                tmpItem = items[x];
                w       = x;

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

                items[w] = tmpItem;
            }
        }
Exemplo n.º 5
0
 public void sort(GLItemCollection items)
 {
     QuickSort(items, 0, items.Count - 1);
     GLInsertionSort(items, 0, items.Count - 1);
 }