学习型 ASP/PHP/ASP.NET 主机 30元/年全能 ASP/PHP/ASP.NET 主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付
发新话题
打印

大家看看我这段程序哪里错了

大家看看我这段程序哪里错了

我写了个快速排序的程序,运行到sh.Sort(iArrary)这里的时候,出现No overload for method 'Sort' takes '1' arguments的提示,麻烦大家看看,我这个程序是哪儿错了,该怎样去改。谢谢!

using System;

using System.IO;

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();
            }
        }

    }
}

TOP

是那里错了,  sh.Sort(iArrary);你这句话是调用public void Sort(int[] list, int low, int high),Sort你定义的是三个参数,sh.Sort(iArrary)括号里只有一个参数,所以出错

TOP

谢谢!

TOP

这个程序你你调用SORT方法,而你定义SORT方式时传过来的是3个参数,而你最后在调用是只输入了1个,所以报错```

TOP

发新话题