• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
阳光DE我
博客园    首页    新随笔    联系   管理    订阅  订阅

帮下忙!

谁能告诉我主函数里要怎么用sort函数?sort(?,?,?)

下面是快速排序算法程序:

 

 class Program
    {
        private void swap(ref int l, ref int r)
        {
            int temp;
            temp = l;
            l = r;
            r = temp;
        }
        public void sort(int[] list, int low, int high)
        {

            int pivot;//存储分支点
            int l, r;
            int mid;
            if (high <= low)
                return;
            else if (high == low + 1)
            {
                if (list[low] > list[high])
                    swap(ref list[low], ref list[high]);
                return;
            }
            mid = (low + high) >> 1;
            pivot = list[mid];
            swap(ref list[low], ref list[mid]);
            l = low + 1;
            r = high;
            do
            {
                while (1 <= r && list[l] < pivot)
                    l++;
                while (list[r] >= pivot)
                    r--;
                if (l < r)
                    swap(ref list[l], ref list[r]);


            } while (l < r);
            list[low] = list[r];
            list[r] = pivot;
            if (low + 1 < r)
                sort(list, low, r - 1);
            if (r + 1 < high)
                sort(list, r + 1, high);

        }
        static void Main(string[] args)
        {

            int[] list = { 1, 5, 6, 8, 45, 68, 27, 78, 68, 248, 57, 11 };
            Console.ReadKey();
        }
    }
}

posted @ 2009-04-27 22:21  阳光DE我  阅读(134)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3