| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 817 人关注过本帖
标题:大家看看我这段程序哪里错了
只看楼主 加入收藏
sdnd2000
Rank: 1
等 级:新手上路
帖 子:24
专家分:0
注 册:2008-4-10
收藏
 问题点数:0 回复次数:3 
大家看看我这段程序哪里错了
我写了个快速排序的程序,运行到sh.Sort(iArrary)这里的时候,出现No overload for method 'Sort' takes '1' arguments的提示,麻烦大家看看,我这个程序是哪儿错了,该怎样去改。谢谢!

using System;

using

using System.Data;

namespace coreQuickSort
{

    public class QuickSort
    {

        private void Swap(ref int i, ref int j)
        //swap two integer
        {
            int t;
            t = i;
            i = j;
            j = t;
        }

        public QuickSort()
        { }
        public void Sort(int[] list, int low, int high)
        {
            if (high <= low)
            {
                //only one element in array list
                //so it do not need sort
                return;
            }
            else if (high == low + 1)
            {
                //means two elements in array list
                //so we just compare them
                if (list[low] > list[high])
                {
                    //exchange them
                    Swap(ref list[low], ref list[high]);
                    return;
                }
            }

            //more than 3 elements in the arrary list
            //begin QuickSort
            myQuickSort(list, low, high);
        }

        public void myQuickSort(int[] list, int low, int high)
        {
            if (low < high)
            {
                int pivot = Partition(list, low, high);
                myQuickSort(list, low, pivot - 1);
                myQuickSort(list, pivot + 1, high);
            }
        }

        private int Partition(int[] list, int low, int high)
        {
            //get the pivot of the arrary list
            int pivot;
            pivot = list[low];
            while (low < high)
            {
                while (low < high && list[high] >= pivot)
                {
                    high--;
                }
                if (low != high)
                {
                    Swap(ref list[low], ref list[high]);
                    low++;
                }
                while (low < high && list[low] <= pivot)
                {
                    low++;
                }
                if (low != high)
                {
                    Swap(ref list[low], ref list[high]);
                    high--;
                }
            }
            return low;
        }

        public class MainClass
        {
            public static void Main()
            {
                int[] iArrary = new int[] { 1, 5, 13, 6, 10, 55, 99, 2, 87, 12, 34, 75, 33, 47 };
                QuickSort sh = new QuickSort();
                sh.Sort(iArrary); //就是这里有点问题
                for (int m = 0; m < iArrary.Length; m++)
                    Console.Write("{0} ", iArrary[m]);
                Console.WriteLine();
            }
        }

    }
}
搜索更多相关主题的帖子: using int Sort System 
2008-04-19 07:26
aubblove
Rank: 1
等 级:新手上路
帖 子:117
专家分:0
注 册:2007-8-18
收藏
得分:0 
是那里错了,  sh.Sort(iArrary);你这句话是调用public void Sort(int[] list, int low, int high),Sort你定义的是三个参数,sh.Sort(iArrary)括号里只有一个参数,所以出错
2008-04-19 10:27
sdnd2000
Rank: 1
等 级:新手上路
帖 子:24
专家分:0
注 册:2008-4-10
收藏
得分:0 
谢谢!
2008-04-19 11:25
Andylauzxb
Rank: 1
等 级:新手上路
帖 子:30
专家分:0
注 册:2007-10-15
收藏
得分:0 
这个程序你你调用SORT方法,而你定义SORT方式时传过来的是3个参数,而你最后在调用是只输入了1个,所以报错```
2008-04-20 21:45
快速回复:大家看看我这段程序哪里错了
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.035942 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved