当前位置: 首页 > news >正文

做图网站被告中南建设集团有限公司

做图网站被告,中南建设集团有限公司,大良用户网站建设,蓝盟it外包归并排序 归并算法采用非常经典的分治策略,每次把序列分成n/2的长度,将问题分解成小问题,由复杂变简单。 因为使用了递归算法,不能用于大数据的排序。 核心代码: using System; using System.Text; using System.Co…

归并排序

归并算法采用非常经典的分治策略,每次把序列分成n/2的长度,将问题分解成小问题,由复杂变简单。

因为使用了递归算法,不能用于大数据的排序。

核心代码:

using System;
using System.Text;
using System.Collections.Generic;
using System.Windows.Forms;

namespace WindowsFormsApp6
{
    public partial class Form1 : Form
    {
        Random rnd = new Random((int)DateTime.Now.Ticks);
        List<string> slides = new List<string>();

        public Form1()
        {
            InitializeComponent();
            BrowserReleaseHelper.SetWebBrowserFeatures(11);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.Text = "C#,四种常见排序算法的可视化编程——北京联高软件开发有限公司";
            button1.Text = "选择排序"; button1.Cursor = Cursors.Hand;
            button2.Text = "冒泡排序"; button2.Cursor = Cursors.Hand;
            button3.Text = "插入排序"; button3.Cursor = Cursors.Hand;
            button4.Text = "快速(递归)"; button4.Cursor = Cursors.Hand;
            button5.Text = "快速(非递归)"; button5.Cursor = Cursors.Hand;
            button6.Text = "归并排序"; button6.Cursor = Cursors.Hand;
            panel1.Dock = DockStyle.Top;
            panel2.Dock = DockStyle.Fill;
            webBrowser1.Navigate("http://www.315soft.com");
        }

        private int[] RandArray()
        {
            int n = 20;
            int[] dataArray = new int[n];
            for (int i = 0; i < n; i++)
            {
                dataArray[i] = rnd.Next(20, 100);
            }
            return dataArray;
        }

        private void button6_Click(object sender, EventArgs e)
        {
            int[] arraySource = RandArray();
            int[] arrayTemplate = new int[arraySource.Length];
            MergeSort(0, arraySource.Length - 1, ref arraySource, ref arrayTemplate);

            loop = 0;
            timer1.Interval = 100;
            timer1.Enabled = true;
        }

        /// <summary>
        /// 归并排序算法
        /// </summary>
        /// <param name="left"></param>
        /// <param name="right"></param>
        /// <param name="arraySource"></param>
        /// <param name="arrayTemplate"></param>
        private void MergeSort(int left, int right, ref int[] arraySource, ref int[] arrayTemplate)
        {
            if (left >= right)
            {
                return;
            }
            int mid = (left + right) >> 1;
            MergeSort(left, mid, ref arraySource, ref arrayTemplate);
            MergeSort(mid + 1, right, ref arraySource, ref arrayTemplate);
            int head_left = left;
            int head_right = mid + 1;
            int tmp_index = left;
            while (head_left <= mid && head_right <= right)
            {
                if (arraySource[head_left] < arraySource[head_right])
                {
                    arrayTemplate[tmp_index++] = arraySource[head_left++];
                }
                else
                {
                    arrayTemplate[tmp_index++] = arraySource[head_right++];
                }
            }
            while (head_left <= mid)
            {
                arrayTemplate[tmp_index++] = arraySource[head_left++];
            }
            while (head_right <= right)
            {
                arrayTemplate[tmp_index++] = arraySource[head_right++];
            }
            for (int i = left; i <= right; i++)
            {
                arraySource[i] = arrayTemplate[i];
            }

            slides.Add(Slide(button6.Text, arraySource, left, right));
        }

        private string Slide(string title, int[] dataArray, int a, int b)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");
            sb.AppendLine("<html xmlns=\"http://www.w3.org/1999/xhtml\" >");
            sb.AppendLine("<head>");
            sb.AppendLine("<style>");
            sb.AppendLine("td { vertical-align:bottom;text-align:center;font-size:12px; } ");
            sb.AppendLine(".bar { width:" + (int)((webBrowser1.Width - dataArray.Length * 11) / dataArray.Length) + "px;font-size:12px;border:solid 1px #FF6701;background-color:#F08080;text-align:center;border-radius:3px; }");
            sb.AppendLine("</style>");
            sb.AppendLine("</head>");
            sb.AppendLine("<body>");
            sb.AppendLine("<table width='100%' style='border-bottom:solid 1px #E9E9E0;'>");
            sb.AppendLine("<tr>");
            sb.AppendLine("<td>方法:" + title + "</td>");
            sb.AppendLine("<td>数据:" + dataArray.Length + "</td>");
            sb.AppendLine("<td>步骤:[0]</td>");
            sb.AppendLine("</tr>");
            sb.AppendLine("</table>");
            sb.AppendLine("<br>");
            sb.AppendLine("<table width='100%' style='border-bottom:solid 15px #E9E9E0;'>");
            sb.AppendLine("<tr>");
            for (int i = 0; i < dataArray.Length; i++)
            {
                if (i == a || i == b)
                {
                    sb.AppendLine("<td>" + dataArray[i] + "<div class='bar' style='height:" + dataArray[i] * 3 + "px;background-color:#993333;'></div></td>");
                }
                else
                {
                    sb.AppendLine("<td>" + dataArray[i] + "<div class='bar' style='height:" + dataArray[i] * 3 + "px;'></div></td>");
                }
            }

            sb.AppendLine("</tr>");
            sb.AppendLine("</table>");
            sb.AppendLine("</body>");
            sb.AppendLine("</html>");
            return sb.ToString();
        }


        int loop = 0;

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (loop < slides.Count + (3000 / timer1.Interval))
            {
                if (loop < slides.Count)
                {
                    webBrowser1.DocumentText = slides[loop].Replace("[0]", loop + " / " + slides.Count);
                    loop++;
                    return;
                }
                loop++;
                return;
            }
            loop = 0;
        }
    }
}
 

 ——————————————————————

POWER BY 315SOFT.COM &
TRUFFER.CN

http://www.hkea.cn/news/359668/

相关文章:

  • 做外贸做的很好的网站全国疫情突然又严重了
  • 开发app需要什么样的团队百度seo优化培训
  • ftp上传网站之后软文什么意思范例
  • 询广西南宁网站运营推广系统
  • wordpress侧边栏小工具佛山网站优化
  • 用vs做网站原型企业培训课程有哪些内容
  • wordpress评论自定义百度刷排名seo
  • 四川建设网官网登录入口泉州seo外包
  • 网站有备案 去掉备案网络营销意思
  • 新建网站推广给企业百度问一问在线咨询客服
  • 曹鹏wordpress建站seo视频广东疫情防控措施
  • 网站开发的岗位排名优化工具
  • 岳阳做网站怎么做推广让别人主动加我
  • 不断改进网站建设公司百度官网优化
  • 万户网站宁波网站制作优化服务
  • 潍坊快速网站排名网站是怎么做出来的
  • 聚美优品的pc网站建设注册网址
  • 陕西省住房与城乡建设厅网站免费b站推广软件
  • 淮南市住房与城乡建设部网站网店买卖有哪些平台
  • 网页qq表情佛山百度快速排名优化
  • 网站建设方案论文1500社会新闻最新消息
  • 网站组建 需求分析市场监督管理局职责
  • 云课堂哪个网站做的好厦门关键词优化seo
  • 中企动力沈阳分公司seo免费诊断电话
  • 网站vps被黑湖人最新排名最新排名
  • 如何夸奖客户网站做的好seo课程心得体会
  • 有哪些做电子商务的网站时空seo助手
  • 临沂百度网站电脑培训机构哪个好
  • 无锡专业做网站的公司怎样把自己的产品放到网上销售
  • 大学网站建设管理办法推广技巧