分享

分治法:用C#实现归并排序

 命運之輪 2010-04-15

根据《算法设计与分析基础》中对归并排序的描述,写了一分C#代码实现。
具体的实现代码如下:

  1using System;
  2using System.Collections.Generic;
  3using System.Text;
  4
  5namespace MergeSort
  6{
  7    class Program
  8    {
  9        static void Main(string[] args)
 10        {
 11            Program p = new Program();
 12
 13            int[] a = new int[] 4216360-511 };
 14
 15            p.Sort(a);
 16
 17            for (int i = 0; i < a.Length; i++)
 18            {
 19                System.Console.WriteLine(a[i]);
 20            }

 21        }

 22
 23        /**/
 28        public int[] Sort(int[] toBeSort)
 29        
 45
 46        /**/
 52        private void merger(int[] part1, int[] part2, int[] toBeSort)
 53        
 88
 89        /**/
 94        private int[] get2Part(int[] toBeSort)
 95        
103
104        /**/
109        private int[] get1Part(int[] toBeSort)
110        
118    }

119}

120

对于分治法的效率分析,有一个通用的公示可以使用:通用分治递推公式。

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约