⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fastsort.cs

📁 数据结构排序算法演示数据结构排序算法演示数据结构排序算法演示数据结构排序算法演示数据结构排序算法演示数据结构排序算法演示数据结构排序算法演示
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.Text;

namespace GraphicsSort
{
    public class FastSort:SortBase, ISortable
    {
        public FastSort(int[] initList, System.Windows.Forms.Control ctlToDraw)
            : base("FastSort", initList, ctlToDraw)
        {
            
        }

        #region ISortable 成员

        public void Sort()
        {
            SwapCount = 0;
            IsComplete = false;
            SortPart(0, list.Length - 1);
            IsComplete = true;
            if (sortComplete != null)
            {
                SortEventArgs e = new SortEventArgs();
                e.SwapCount = SwapCount;
                e.SortName = SortName;
                foreach (SortComplete sc in sortComplete.GetInvocationList())
                {
                    sc(ctl, e);
                }
            }
        }

        private void SortPart(int startpos, int endpos)
        {
            if (startpos >= endpos)
                return;
            int i, j;
            i = startpos;
            j = endpos;
            while (i < j)
            {
                while ((list[i] <= list[j]) && (i < j))
                    j--;
                if (i < j)
                {
                    //mut.WaitOne();
                    int tmp = list[i];
                    list[i] = list[j];
                    list[j] = tmp;
                    //mut.ReleaseMutex();
                    i++;
                    SwapCount++;
                }
                while ((list[i] <= list[j]) && (i < j))
                    i++;
                if (i < j)
                {
                    //mut.WaitOne();
                    int tmp = list[i];
                    list[i] = list[j];
                    list[j] = tmp;
                    //mut.ReleaseMutex();
                    j--;
                    SwapCount++;
                }
                foreach (StepComplete sc in stepComplete.GetInvocationList())
                {
                    sc(ctl, e);
                }

            }
            SortPart(startpos, i-1);
            SortPart(i + 1, endpos);
        }

        #endregion

        public override event StepComplete stepComplete;
        public override event SortComplete sortComplete;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -