错误:函数调用中有两个参数

时间:2017-03-25 02:30:17

标签: c++

我正在开发一个程序来衡量合并排序将根据此处的代码对随机元素进行排序所需的秒数:

https://vinayakgarg.wordpress.com/2011/10/25/time-comparison-of-quick-sort-insertion-sort-and-bubble-sort/

http://rextester.com/discussion/MKKVY46370/MergeSort

我收到的错误就是说mergesort(0,length-1); “呼吁中有两个论点”。

        #include <iostream.h>
        #include <fstream.h>
        #include <stdlib.h>
        #include <time.h>

        void mergesort(int list[],int i,int j); void merge(int list[],int i1,int j1,int i2,int j2);


        long length = 1000; const long max_length = 3000;

        int list[max_length];


        void read() {
            ifstream fin("rand.dat", ios::binary);
            for (long i = 0; i < length; i++)
            {   fin.read((char*)&list[i], sizeof(int));
            }
            fin.close(); }

        void mergesort(int list[],int i,int j) {
            int mid;

            if(i<j)
            {
                mid=(i+j)/2;
                mergesort(list,i,mid);        //left recursion
                mergesort(list,mid+1,j);    //right recursion
                merge(list,i,mid,mid+1,j);    //merging of two 

        sorted sub-arrays
            } }   void merge(int list[],int i1,int j1,int i2,int j2) {
            int temp[1000];    //array used for merging
            int i,j,k;
            i=i1;    //beginning of the first list
            j=i2;    //beginning of the second list
            k=0;

            while(i<=j1 && j<=j2)    //while elements in both lists
            {
                if(list[i]<list[j])
                    temp[k++]=list[i++];
                else
                    temp[k++]=list[j++];
            }

            while(i<=j1)    //copy remaining elements of the first 

        list
                temp[k++]=list[i++];

            while(j<=j2)    //copy remaining elements of the second 

        list
                temp[k++]=list[j++];

            //Transfer elements from temp[] back to a[]
            for(i=i1,j=0;i<=j2;i++,j++)
                list[i]=temp[j]; }   int main() {



        double t1, t2;



        read();
                t1 = clock();
                mergesort(0, length - 1);
                t2 = clock();
                cout << "Merge Sort\t: " << (t2 - t1)/CLK_TCK << " 

        sec\n";


            switch (length)     {   case 100 :
                length = 500;
                break;  case 500 :
                length = 1000;
                break;  case 1000 :
                length = 1500;
                break;  case 1500 :
                length = 2000;
                break;  case 2000 :
                length = 2500;
                break;  case 2500 :
                length = 3000;
                break;  case 3000 :
                length = 3001;
                break;  }

            }
            return 0;
 }

1 个答案:

答案 0 :(得分:1)

mergesort有3个参数;你只传递2.第一个参数应该是一个数组。