error C2065: 'swapppedElements' : undeclared identifier
"swapppedElements":我定义这个变量是作为一个flag,一个状态变量,
但是自己不知道布尔变量的头文件名和定义方法,求助:
#include"iostream"
#include"iomanip"
using namespace std;
void Swap(int &a,int &b){//exchange
int temp;
temp=a;
a=b;
b=temp;
}//Swap
void BubbleSort(int list[],int n){
int numberOfPairs=n,i;
bool swappedElements;//a flag
swappedElements=true;
while(swappedElements){
numberOfPairs=numberOfPairs-1;
swapppedElements=false;
for(i=1;i<=numberOfPairs;i++)
if(list[i]>list[i+1]){
Swap(list[i],list[i+1]);
swappedElements=true;
}//if
}//while
cout<<"The new list is:\n";
for(i=1;i<=n;i++){
cout<<setw(2)<<list[i]<<" ";
if(i%10==0)
cout<<"\n";
}//for
}//BubbleSort
int main(){
int a[101],i;
a[0]=0;
for(i=1;i<101;i++){//create a array
a[i]=rand()%100;
a[0]++;
}//for
cout<<"\nThe original elements are:\n";
for(i=1;i<101;i++){//output the array
cout<<setw(2)<<a[i]<<" ";
if(i % 10 == 0)
cout << "\n";
}//for
cout<<endl<<endl;
BubbleSort(a, 100);
return 0;
}//main