-1

I have an error that the bsort(array[],a] has a 69 C:\Users\heide\Desktop\Exam.cpp expected primary-expression before ']' token also the search(array[],a,b)

Can u please help me to finish this? Here is the code:

#include<iostream>
using namespace std;

struct Sort{

   void search(int array[],int x,int y)
   {
      for(int i=0;i<=x;i++)
      {
         if(array[i]==y)
         {
            cout<<"The number you enter appeared on array number "<<i<<endl;
         }
         else
         {
            cout<<"ERROR"<<endl;
         }
      }
   }
   void swap(int *x,int *y)
   {
      int i=0;
      i=*x;
      *x=*y;
      *y=i;
   }
   void bsort(int array[],int x)
   {
       for(int a=0;a<x-1;a++)
       {
           for(int b=0;b<x-1;b++)
           {
               if(array[a]> array[b])
               {
                  swap(&array[a],&array[b]);
                  for(int i=0;i<=x;i++)
                  {
                     cout<<array[i]<<"\t";
                  }
                  cout<<endl;
               }
           }
       }
   }
};

int main()
{
   Sort sort;
   int a;
   int b;
   cout<<"Enter the number of elements in the array "<<endl;
   cin>>a;
   int array[a];
   for(int i=0; i<=a;i++)
   {
      cout<<"Enter Number for Element "<<i<<": "<<endl;
      cin>>array[i];
   }
   cout<<"The List Before Sorting"<<endl;
   for(int i=0;i<=a;i++)
   {
      cout<<array[i]<<"\t"<<endl;
   }
   cout<<"Elements Will is Sorting....."<<endl;
   sort.bsort(array[],a);
   cout<<"Enter The Number Needed to be Searched "<<endl;
   cin>>b;
   sort.search(array[],a,b);
   system("pause");
   return 0;
}
4

1 回答 1

3

在调用 bsort 函数时删除方括号 []。它应该是

sort.bsort(array,a);
于 2013-10-15T12:42:28.977 回答