我有bsort(array[],a] has a 69 C:\Users\heide\Desktop\Exam.cpp expected primary-expression before ']' token
的错误
也是search(array[],a,b)
#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;
}
答案 0 :(得分:3)
在调用bsort函数时删除方括号[]。它应该是
sort.bsort(array,a);